Definition | #include <stdlib.h> double strtod(const char *s, char **p); These functions convert the string to which s points into a floating-point number of type
Any control character for white space may be used for tab (see definition under
If p is a NULL pointer,
| |
Return val. | Floating-point number of type | |
for strings which are structured as described above and represent a numeric value within the permissible floating-point range. | ||
0 | for strings that do not conform to the syntax described above or do not begin with convertible characters. | |
| depending on the function type and the sign of x, for strings whose numeric value lies outside the permissible floating-point range. | |
Note | The decimal point character (period or comma) in the string to be converted is determined by the locale (category LC_NUMERIC). The default setting is a period. | |
Example | The following program converts a string passed during the call (Enter Options) into its corresponding floating-point number and outputs the first non-convertible character, if any. #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
/* Numbers are passed as strings!!
A conversion is necessary if the
numeric value is required */
{
char *p;
printf("floating : %f\n", strtod(argv[1], &p));
putchar(*p);
return 0;
}
| |
See also | atof, atoi, atol, strtol, strtoul | |