唉,感谢楼上,吃饭去了,怎么就没反过来想一下呢?总是想将整型转换为字符串.可能是饿了吧,下面改了一下,answer就是你想要的结果.
#define LEN 20
#include"stdio.h"
#include <stdlib.h>
main()
{
char x[LEN];
int i,sign,answer;
do
{
i=0,sign=1;
printf("Input:");
scanf("%s",&x);
while(x[i]){if(x[i]<48||x[i]>57) {sign=0;break;}i++;}
if(sign==1) {break; printf("%s\n",x); }
}
while(1);
answer=atoi(x); /*将字符串转换为整型*/
printf("%d",answer);
}