Write a function to implement library function Atoi, convert the string into shaping # include <stdio.h> #include <string.h>int my_atoi (const char *src) {int flag=1; int Sum=0;while (*SRC) {if (*src = = ") Src++;else if (*src = = ' + ') {Src++;flag = 1;} else if (*src = = '-') {src++;flag =-1;} else if (*src >= ' 0 ' &&*src <= ' 9 ') {sum = sum * + (*SRC-' 0 '); src++;} Else{return 0;}} sum = Sum*flag;return sum;} int main () {printf ("%d\n", My_atoi ("+12345"));p rintf ("%d\n", My_atoi (" -12345"));p rintf ("%d\n", My_atoi ("+12345")); printf ("%d\n", My_atoi (" -12345"));p rintf ("%d\n", My_atoi ("123") );p rintf ("%d\n", My_atoi ("234 5")); printf ("%d\n", My_atoi (""));p rintf ("%d\n", My_atoi ("123ab")); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The "C Language" write function implements the library function Atoi, transforms the string into the shaping