#include <stdlib.h>
|
double
strtod (const char * restrict nptr, char ** restrict endptr); |
float
strtof (const char * restrict nptr, char ** restrict endptr); |
long double
strtold (const char * restrict nptr, char ** restrict endptr);
|
If endptr is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr.
If no conversion is performed, zero is returned and the value of nptr is stored in the location referenced by endptr.
If the correct value would cause overflow, plus or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the sign and type of the return value), and ERANGE is stored in errno. If the correct value would cause underflow, a value whose magnitude is no greater than the smallest normalized positive number in the return type, ( KMinTReal in case of symbian) shall be returned and ERANGE is stored in errno.
The expected form of the string is an optional plus (+) or minus sign (-) followed by either:
In both cases, the significand may be optionally followed by an exponent. An exponent consists of an E or e (for decimal constants) or a P or p (for hexadecimal constants), followed by an optional plus or minus sign, followed by a sequence of decimal digits. For decimal constants, the exponent indicates the power of 10 by which the significand should be scaled. For hexadecimal constants, the scaling is instead done by powers of 2.
Alternatively, if the portion of the string following the optional plus or minus sign begins with INFINITY or NAN, ignoring case, it is interpreted as an infinity or a quiet NaN, respectively.
In any of the above cases, leading white-space characters in the string (as defined by the isspace function) are skipped. The decimal point character is defined in the programs locale (category LC_NUMERIC).
#include <stdlib.h> #include <stdio.h> int main( void ) { char *endpt = NULL; double d = 0.0; d = strtod("0x00e123bhduitri", &endpt); printf("{Expected: 922171.0} %f\n", d); printf("{Expected: \"hduitri\"} %s\n", endpt); return 0; }
Output
{Expected: 922171.0} 922171.0 {Expected: "hduitri"} hduitri
[ERANGE] | |
Overflow or underflow occurred. | |
© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user. |