double atof (const char* str);
double."C" locale is formed by an optional sign character (+ or -), followed by a sequence of digits, optionally containing a decimal-point character (.), optionally followed by an exponent part (an e or E character followed by an optional sign and a sequence of digits)."C" locale is formed by an optional sign character (+ or -), followed by one of:.), optionally followed by an exponent part (an e or E character followed by an optional sign and a sequence of digits).0x or 0X prefix, then a sequence of hexadecimal digits (as in isxdigit ) optionally containing a period which separates the whole and fractional number parts. Optionally followed by a power of 2 exponent (a p or P character followed by an optional sign and a sequence of hexadecimal digits).INF or INFINITY (ignoring case).NAN or NANsequence (ignoring case), where sequence is a sequence of characters, where each character is either an alphanumeric character (as in isalnum ) or the underscore character (_).0.0.double value.0.0).double, it causes undefined behavior. See strtod for a more robust cross-platform alternative when this is a possibility.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* atof example: sine calculator */
#include <stdio.h> /* printf, fgets */
#include <stdlib.h> /* atof */
#include <math.h> /* sin */
int main ()
{
double n,m;
double pi=3.1415926535;
char buffer[256];
printf ("Enter degrees: ");
fgets (buffer,256,stdin);
n = atof (buffer);
m = sin (n*pi/180);
printf ("The sine of %f degrees is %f\n" , n, m);
return 0;
}
Enter degrees: 45 The sine of 45.000000 degrees is 0.707101
double, it causes undefined behavior.