strtod/strtol/strtoul
7-56
Convert String to Numeric Value
strtod/strtol/
strtoul
Syntax
#include <stdlib.h>
double
strtod
(const char *test, char **endptr);
long int
strtol
(const char *test, char **endptr, int base);
unsigned long int
strtoul
(const char *test, char **endptr, int base);
Defined in
strtod.c in rts.src, strtol.c in rts.src and strtoul.c in rts.src
Description
Three functions convert ASCII strings to numeric values. For each function,
argument test points to the original string. Argument endptr points to a pointer;
the functions set this pointer to point to the first character after the converted
string. The functions that convert to integers also have a third argument, base,
which tells the function what base to interpret the string in.
-
The strtod function converts a string to a floating-point value. The string
must have the following format:
[
space
] [
sign
]
digits
[
.digits
] [e|E
[
sign
]
integer
]
The function returns the converted string; if the original string is empty or
does not have the correct format, the function returns a 0. If the converted
string would cause an overflow, the function returns
"
HUGE_VAL; if the
converted string would cause an underflow, the function returns 0. If the
converted string causes an overflow or an underflow, errno is set to the
value of ERANGE.
-
The strtol function converts a string to a long integer. The string must have
the following format:
[
space
] [
sign
]
digits
[.
digits
] [e|E [
sign
]
integer
]
-
The strtoul function converts a string to an unsigned long integer. The
string must have the following format:
[
space
] [
sign
]
digits
[.
digits
] [e|E [
sign
]
integer
]
The space is indicated by a space bar, horizontal or vertical tab, carriage re-
turn, form feed, or new line. Following the
s
pace is an optional sign and digits
that represent the integer portion of the number. The fractional part of the num-
ber follows, then the exponent, including an optional sign.
The first unrecognized character terminates the string. The pointer that endptr
points to is set to point to this character.
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...