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
5 ★ | 1 Vote
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
Instructions to remove DirectX 11, restore default DirectX
How do astronauts drink coffee in space?
Instructions for creating PowerPoint background color effects - Create a new background for slides
Instructions for installing and registering a Steam account on your computer
How to create strong id, nickname, username, 'Strong Username'
How to use Structure Reference and Style Reference in Adobe Firefly