#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int ascii_to_integer(char *str)
{
int i = 0;
while(*str != '\0')
{
if(*str > '0'&& *str < '9')
{
i = i * 10 + *str - 48;
str++;
}
else
str++;
}
return i;
}
int main()
{ int b = 0;
char *a=NULL;
a = (char*)malloc(100*sizeof(char));
scanf("%s",a);
b = ascii_to_integer(a);
printf("b = %d\n",b);
return 0;
}
这个字符串参数必须个数字,函数应该把这些数字字符转换为整数并返回这个整数。如果字符串参数包含了任何非数字字符,函数就返回零。请不必担心算数溢出。
最新推荐文章于 2022-11-24 10:27:52 发布