//simulation implementation of the ATOF function of library functions # include <stdio.h> #include <string.h> #include < assert.h> #include <ctype.h>double my_atof (char const *p) {DOUBLE ret = 0;int flag = 1;int count = 0;assert (P! = NU LL); while (Isspace (*p)) {p++;} while (*p) {if (count) {count = Count * 10;} if (*p = = ' + ') p++;else if (*p = = '-') {p++;flag =-1;} else if (*p = = '. ') {count++;p + +;} else if (*p >= ' 0 ' && *p <= ' 9 ') {ret = ret * + (*p-' 0 ');p + +;} Elsereturn 0;} return ret*flag/count;} int main () {printf ("%f\n", My_atof ("+23.45"));p rintf ("%f\n", My_atof (" -2.345"));p rintf ("%f\n", My_atof ("+234.5")); printf ("%f\n", My_atof (" -23.45"));p rintf ("%f\n", My_atof ("2.345"));p rintf ("%f\n", My_atof ("234.5"));p rintf ("%f\n" , My_atof (".")); printf ("%f\n", My_atof ("12.3ab")); return 0;}
The Atof function of "C language" simulation to implement library function