整数转化为整数字符串

题目:把一串整数转化为整数字符串,并且不用itoa。

还有的题目是把整数字符串转化为整数。有空再补上。

#include<iostream> 
#include<stdio.h>
const int N = 10;

int main()
{
	int num = 123456789, i = 0, j = 0;
	//std::cin >> num;
	char temp[N],Str[N];
	while(num){
		temp[i++] = num%10 + '0';// + '0',自动转化 ,num%10 求最后一位 
		num = num/10;//去除最后一位		
	}
	temp[i] = 0;
	printf("temp is %s\n",temp);
	//std::cout << "temp is " << temp << std::endl;
	i = i -1;//回退一位到数字位上 
	while(i>=0){
		Str[j++] = temp[i--];
	}
	//最后一位完后,此时i为负一,跳出循环 
	Str[j] = 0;
	
	//std::cout << i << std::endl;
	
	printf("temp is %s\n",Str);
	//std::cout << "temp is " << SStr << std::endl;
}

 
 

有更好的方法,希望能分享一下。




你可能感兴趣的:(整数转化为整数字符串)