atof/atoi/atol
7-25
Run-Time-Support Functions
Convert String to Number
atof/atoi/atol
Syntax
#include <stdlib.h>
double
atof
(const char *st);
int
atoi
(const char
*
st);
long int
atol
(const char *st);
Defined in
atof.c and atoi.c, in rts.src
Description
Three functions convert strings to numeric representations:
-
The atof function converts a string to a floating-point value. Argument st
points to the string; the string must have the following format:
[
space
] [
sign
]
digits
[
.digits
] [e|E [
sign
]
integer
]
-
The atoi function converts a string to an integer. Argument st points to the
string; the string must have the following format:
[
space
] [
sign
]
digits
-
The atol function converts a string to a long integer. Argument st points to
the string; the string must have the following format:
[
space
] [
sign
]
digits
The
space
is indicated by a space (character), a horizontal or vertical tab, a
carriage return, a form feed, or a new line. Following the space is an optional
sign
, and the
digits
that represent the integer portion of the number. The frac-
tional part of the number follows, then the exponent, including an optional sign.
The first character that cannot be part of the number terminates the string.
Since int and long are functionally equivalent in TMS320C2x/C2xx/C5x C, the
atoi and atol functions are also functionally equivalent.
The functions do not handle any overflow resulting from the conversion.
Example
int i;
double d;
i =
atoi
(“−3291”);
/* i = −3291 */
d =
atof
(“1.23e−2); /* d = .0123 */
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...