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
Traveling with Kids: How to Make Your Trip Fun and Stress-Free
Instructions for recording live video on ChatGPT Voice
One Piece: Strength Ranking of Straw Hat Crew Members
Instructions for inserting stickers into photos on iPhone
FBI Warns iMessage Is Not a Strongly Encrypted Messaging App
Google Labs Releases Whisk: A Tool That Allows You to Upload Images as Instructions Instead of Text Prompts