Atof () function in C
The double atof function (const char * str) in Standard C Library converts a string pointed to by parameter str to a floating point number (type double).
The double atof function (const char * str) in Standard C Library converts a string pointed to by parameter str to a floating point number (type double).
Declare atof () function in C
Below is the declaration for the atof () function in C:
double atof ( const char * str )
Parameters
str - This is a string with a representation of a floating point number.
Returns the value
This function returns the floating point number that was converted as a double value. If no valid conversion is performed, it returns 0.0.
For example
The following C program illustrates the usage of the atof () function in C:
#include #include #include int main () { float val ; char str [ 20 ]; strcpy ( str , "98993489" ); val = atof ( str ); printf ( "Gia tri duoi dang chuoi = %s, nGia tri duoi dang so thuc = %fn" , str , val ); strcpy ( str , "QTM.com" ); val = atof ( str ); printf ( "nGia tri duoi dang chuoi = %s, nGia tri duoi dang so thuc = %fn" , str , val ); return ( 0 ); }
Compile and run the above C program to see the results.
According to Tutorialspoint
Last lesson: stdlib.h in C
Next lesson: The function atoi () in C
You should read it
- The function atoi () in C
- The atol () function in C
- The function strtod () in C
- The function getenv () in C
- The sprintf () function in C
- Function setbuf () in C
- Function strtoul () in C
- Function strtol () in C
- The function perror () in C
- Function puts () in C
- Function putc () in C
- The function vsprintf () in C
Maybe you are interested
NASA announced its plan to search for extraterrestrial life Is Proxima b our 'neighbor' planet? Why have scientists found Proxima b - '2nd Earth' until now? The mystery of the numbers of Proxima b: The 'Second Earth' on the planet may exist life Unbelievable coincidence in history makes the whole world astounded Kepler detects three new exoplanets orbiting 'super-Earth'