您的位置:首页 > 其它

整数转化为整数字符串

2015-07-29 23:44 211 查看
题目:把一串整数转化为整数字符串,并且不用itoa。

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

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

int main()
{
int num = 123456789, i = 0, j = 0;
//std::cin >> num;
char temp
,Str
;
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;
}




有更好的方法,希望能分享一下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: