Atof : String to Float >> Math.h Function >> Header File in C
Atof :
- atof : Interpret it as [A to F] = Alphabet to Float
- atof converts a String to a floating point
- atof converts the string *s to double.
- Header File : Math.h
Which String Format can be Converted into Double / Float ?
- An Optional String of Tabs and Spaces
- An Optional Sign
- A string of digits and an optional decimal point i.e [ digits on both sides of the decimal point ]
- An optional e or E followed by an optional signed integer
Atof Also Recognize ?
- +INF and -INF (plus and minus infinity)
- +NAN and -NAN (Not-a-Number)
Syntax :
double atof(const char *s);Live Example :
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
float f;
char *str = "12345.67";
f = atof(str);
printf("string = %s float = %fn", str, f);
return 0;
}Note :
- In atof, the first unrecognized character ends the conversion.
- On success, these functions return the converted value of the input string.
- If there is an overflow, atof and _atold:
■ return plus or minus HUGE_VAL
■ set errno to ERANGE
■ do NOT call matherr or _matherrl