概述
(1) int ascii_to_integer(char *str)函数实现。
要求:这个字符串参数必须包含一个或者多个数字,函数应该把这些数字转换为整数并且返回这个整数。如果字符串参数包含任何非数字字符,函数就返回零。不必担心算数溢出。
提示:你每发现一个数字,把当前值乘以10,并把这个值和新的数字所代表的值相加。
直接上代码:
#include <stdio.h>
#include <assert.h>
int ascii_to_integer(char *str)
{
int n = 0;
assert(str);
while(*str != '