The strtod, strtol, and strtoul functions convert a character string to a
double-precision value, a long-integer value, or an unsigned-long-integer
value, respectively. The input string is a sequence of characters that can
be interpreted as a numerical value of the specified type. If the strtod
function appears in a compact- or large-model program, nptr can be a maximum
of 100 characters in length.
These functions stop reading the string at the first character they cannot
recognize as part of a number. This character may be the null ('\0') at the
end of the string. With strtol or strtoul this terminating character can
also be the first numeric character greater than or equal to base. If endptr
is not the null character, it points to the character that stopped the scan.
The strtod function expects nptr to point to a string with the following
form:
[whitespace] [sign] [digits] [.digits] [ { d | D | e | E } [sign] digits]
The first character that doesn't fit this form stops the scan.
The strtol function expects nptr to point to a string with the following
form:
[whitespace] [sign] [O] [ { x | X } ] [digits]
The strtoul function expects nptr to point to a string having this form:
[whitespace] [O] [ { x | X } ] [digits]
If base is between 2 and 36, then it is used as the base of the number. If
base is 0, the initial characters of the string pointed to by nptr are used
to determine the base: if the first character is 0 and the second character
is a digit '0' - '7', then the string is interpreted as an octal integer; if
the first character is '0' and the second character is 'x' or 'X', then the
string is interpreted as a hexadecimal integer; if the first character is
'1' - '9', then the string is interpreted as a decimal integer. The letters
from 'a' through 'z' (or 'A' through 'Z') are assigned the values 10 - 35;
only letters whose assigned values are less than base are permitted.
Return Value
The strtod function returns the value of the floating-point number, except
when the representation would cause an overflow, in which case it returns
+\- HUGE_VAL. The function returns 0 if no conversion could be performed or
an underflow occurred.
The strtol function returns the value represented in the string, except when
the representation would cause an overflow, in which case it returns
LONG_MAX or LONG_MIN. The functions returns 0 if no conversion could be
performed.
The strtoul function returns the converted value, if any. If no conversion
can be performed, the function returns 0. The function returns ULONG_MAX on
overflow.
In all three functions errno is set to ERANGE if overflow or underflow
occurs.