c语言一个整数转化成字符串并倒序保存str

如题所述

第1个回答  2014-03-08
#include <stdio.h>
void main() {
int x, i;
char str[11];
printf("? ");
scanf("%d", &x);
printf("%d --> ", x);
i=0;
while(x!=0) {
str[i++]='0'+x%10;
x/=10;
}
str[i]='\0';
for(i=0; str[i]!='\0'; i++) {
printf("[%c]", str[i]);
}
}
/*
C:\cnCode>c5633
? 123456789
123456789 --> [9][8][7][6][5][4][3][2][1]
*/