double strtod (const char* str, char** endptr);
double. If endptr is not a null pointer, the function also sets the value of endptr to point to the first character after the number."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 (_).char*, whose value is set by the function to the next character in str after the numerical value.double.0.0).1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* strtod example */
#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* strtod */
int main ()
{
char szOrbits[] = "365.24 29.53";
char* pEnd;
double d1, d2;
d1 = strtod (szOrbits, &pEnd);
d2 = strtod (pEnd, NULL);
printf ("The moon completes %.2f orbits per Earth year.\n", d1/d2);
return 0;
}
The moon completes 12.37 orbits per Earth year.