很简单的小程序,解决立马给分,在线等
#include <stdio.h>
char s[]={4,5,2,1,};
int atoi(char *ss)//将一串数字装换成相应的数值
{
int i ,n=0;
for(i=0;*ss>='0'&&*ss<='9'&&*ss!='\0';++ss)
n=10*n+(*ss-'0');
printf("%d\n",n);
return n;
}
void main()
{
int m;
m=atoi(s);
printf("%d\n",m);
}
预想的运行结果是输出4521,但是输出的却是0,问题出在哪里呢
[解决办法]
lz把字符串和数值搞混了,2楼正解
[解决办法]
改为 char s[] = "4521" 或者 char s[] = {'4', '5', '2', '1', '\0'};
[解决办法]
char s[]="4521";
{'4','5','2','1',};多了一个,号