Write a function that converts a numeric string to a number corresponding to the string (including a positive floating point, a negative float)//For example: "12.34" returns 12.34. " -12.34 " back to 12.34#include<stdio.h> #include <math.h> #include <assert.h>double my_ Atof (char *str) { int flag=0; int count = 0; int ret = 1; Double sum = 0;assert (NULL!=STR); while (*str! = ') } { if (*str = = '-') { ret =-1; str++; } if (*str = = '. ') { flag = 1; STR + +; } if (*str >= ' 0 ' && *str <= ' 9 ') { sum = sum*10 + (*str-' 0 '); if (flag = = 1) { count + +; } } str++; } sum = Sum/pow (10,count); return ret*sum; } int main () { char p[]= " -52.36"; printf ("%f\n", My_atof (p)); return 0; }
The "C language" writes a function that converts a numeric string to a number corresponding to the string (including positive floating-point numbers, negative floating-point numbers)