C library functions - atof ()
C standard library - <stdlib.h>
description
C library functionsdouble atof (const char * str) to convert a string argument strpoints to a floating-point number (of type double type).
statement
Here it is () declare atof function.
double atof(const char *str)
parameter
- str - the string to be converted to floating-point number.
return value
The function returns the converted double-precision floating-point number, if there is no implementation of an effective conversion, it returns zero (0.0).
Examples
The following example demonstrates the atof () function is used.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { float val; char str[20]; strcpy(str, "98993489"); val = atof(str); printf("字符串值 = %s, 浮点值 = %f\n", str, val); strcpy(str, "w3cschool.cc"); val = atof(str); printf("字符串值 = %s, 浮点值 = %f\n", str, val); return(0); }
Let's compile and run the above program, which will result in the following:
字符串值 = 98993489, 浮点值 = 98993488.000000 字符串值 = w3cschool.cc, 浮点值 = 0.000000