Write the function definition for the following function prototype:
int Ascii_to_integer (char *str);
The string argument must contain one or more numbers, and the function should convert the numeric characters to integers and return the integer. If the string argument contains any non-numeric characters, the function returns zero. Please do not worry about arithmetic overflow.
Tip: The trick is simple: Every number you find, multiply the current value by 10 and add the value to the value represented by the new number. The character pointer minus ' 0 ' will convert its corresponding ASCII value to an integral type.
#include <stdio.h>int ascii_to_integer (char *str) { int i=0; int m=0; int sum=0; char *ch = str; while (*ch! = ') } { if (*ch<48 | | *ch>57) //Determine if the character is a number return 0; i++; ch++; } Ch=str; for (; m<i;m++) { sum=sum*10+ (* (ch+m)-' 0 '); Minus ' 0 ' is the conversion of ASCII to shaping } return sum; int main () { char *str= "123"; int n; N=ascii_to_integer (str); printf ("%d\n", n); return 0;}
Write the function definition for the following function prototype: int Ascii_to_integer (char *str)