ASCII
to
Number
atof/atoi/atol
Syntax
#include
<stdlib.h>
double
atof(nptr)
char
*nptr;
int
atoi(nptr)
char
*nptr;
long
int
atol(nptr)
char
*nptr;
Defined
in
atof
. c and
atoi.
c in
rts.
src
Description
Three functions convert ASCII strings
to
numeric representations:
• The
atof
function converts a string
to
a
floating-point
value.
Argu-
ment
nptr
points
to
the string; the string must have the
following
format:
[space] [sign] digits [.digits]
[el£
[sign] integer]
• The
atoi
function converts a string to
an
integer. Argument
nptr
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
nptr
points
to
the string; the string must have the
following
format:
[space] [sign] digits
The space
is
indicated by a space (from the space bar), a horizontal
or
ver-
tical tab, a carriage return, a form feed, or a newline. Following the space
is
an
optional sign, and then digits that represent the integer portion
of
the
number. The fractional part
of
the number follows, then the exponent,
in-
cluding
an
optional sign.
The first character that cannot be part
of
the number terminates the string.
Since
int and long
are
functionally equivalent in TMS3401 0
C,
the atoi and
atol functions
are
also functionally equivalent.
The functions
do
not
handle any overflow resulting from the conversion.
6-25