字符串数字改为int数字出错,求解···
程序代码:#include<stdio.h>
void main()
{
long fun(char s[]);
long int a;
char str[20];
getchar(str);
a=fun(str);
printf("%ld",a);
}
long fun(char s[])
{
int b=0,i=0,d;
while(s[i]!='\0')
{
if(s[i]='0')
d=0;
else if(s[i]='1')
d=1;
else if(s[i]='2')
d=2;
else if(s[i]='3')
d=3;
else if(s[i]='4')
d=4;
else if(s[i]='5')
d=5;
else if(s[i]='6')
d=6;
else if(s[i]='7')
d=7;
else if(s[i]='8')
d=8;
else if(s[i]='9')
d=9;
i++;
b=10*b+d;
}
return(b);
}运行出来是错的···求高手解答···






