/* Write a function that converts a numeric string to a number corresponding to this string (including positive floating-point numbers, negative floating-point numbers) For example: "12.34" returns 12.34 "123.34" return-123.34 function prototype: Double My_atof (char *str ) */#include <stdio.h>double my_atof (char const *STR) {int count = 0;int n = 0;double p = 0.0;if (*str = = '-') {n = 1;str++;} while (*str! = ') ') {//Judge the decimal if (*str = = '. ') {count++;str++;continue;} Remember the number of decimal moves if (count) {count = Count *;} p = p * + (*STR-' 0 '); str++;} Divide by the number of decimal points p = p/count;if (n = = 1) {p =-p;} return p;} int main () { char *p = " -12.34";p rintf ("converted to:%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)