strtol, atol, atoi
Purpose
Converts a string to an integer.
Library
Standard C Library (libc.a)
Syntax
long strtol (str, ptr, base) long atol (str)
char *str, **ptr; char *str;
int base;
int atoi (str)
char *str;
Description
The strtol subroutine returns a long integer whose value
is represented by the character string str. strtol scans
the string up to the first character that is inconsistent
with the base. Leading white-space characters are
ignored.
Warning: Overflow conditions are ignored.
If the value of ptr is not (char **) NULL, then a pointer
to the character that terminated the scan is stored in
*ptr. If an integer cannot be formed, *ptr is set to
str, and 0 is returned.
If the base parameter is positive and not greater than
36, then it is used as the base for conversion. After an
optional leading sign, leading zeroes are ignored. "0x"
or "0X" is ignored if base is 16.
If the base parameter is 0, the string determines the
base. Thus, after an optional leading sign, a leading 0
indicates octal conversion, and a leading "0x" or "0X"
indicates hexadecimal conversion. The default is to use
decimal conversion.
Note: Truncation from long to int can take place upon
assignment, or by an explicit cast.
The atol (str) subroutine call is equivalent to strtol
(str, (char **) NULL, 10).
The atoi (str) subroutine call is equivalent to (int)
strtol (str, (char **) NULL, 10).
The atoi and atol subroutines do not actually call
strtol.
The strtol, atol, and atoi subroutines perform conver-
sions to integers. See "strtod, atof" for information on
conversions to floating-point numbers.
Related Information
In this book: "strtod, atof" and "scanf, fscanf, sscanf,
NLscanf, NLfscanf, NLsscanf."