函数应该把这些数字字符转换为整数并返回这个整数。如果字符串参数包含了任何非数字字符,函数就返回零。int ascii_to_integer(char *string)
{
int s =0;
while(*string != '/0')
{
if( (*string)<'0' || (*string)>'9' )
return 0;
s = s * 10 + *string-'0';
string++;
}
return s;
}
int main()
{
char ch[100]="123";
printf("%d\n",ascii_to_integer(ch));
return 0;
}
int ascii_to_integer(char *string)
{
int s =0;
while(*string != '/0')
{
if( (*string)<'0' || (*string)>'9' )
return 0;
s = s * 10 + *string-'0';
string++;
}
return s;
}
int main()
{
char ch[100]="123";
printf("%d\n",ascii_to_integer(ch));
return 0;
}