strtol(3) CLIX strtol(3)
NAME
strtol - Converts a string to an integer
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
long strtol(
char *str ,
char **ptr ,
int base );
PARAMETERS
str A pointer to a character string
ptr A pointer to the first character in str not converted
base An integer representing the base of the resulting number
DESCRIPTION
The strtol() function returns, as a long integer, the value represented by
the character string pointed to by str. The string is scanned up to the
first character that is inconsistent with the base. The leading white
space characters (as defined in isspace(3)) are ignored.
If the value of ptr is not (char **)NULL a pointer to the character
terminating the scan is returned in the location pointed to by ptr. If no
integer can be formed, that location is set to str, and zero is returned.
If base is positive and not greater than 36, it is used as the base for
conversion. After an optional leading sign, leading zeros are ignored,
and 0x or 0X is ignored if base is 16.
If base is zero, the string itself determines the base as follows: after
an optional leading sign, a leading zero indicates octal conversion; a
leading 0x or 0X indicates hexadecimal conversion. Otherwise, decimal
conversion is used.
Truncation from long to int occurs upon assignment or by an explicit cast.
EXAMPLES
To return the long and integer values of a string:
foo (string)
char* string;
2/94 - Intergraph Corporation 1
strtol(3) CLIX strtol(3)
{
long L;
int I;
L = strtol(string, (char**)0, 10);
I = atoi (string);
}
RETURN VALUES
If a correct value causes overflow, LONG_MAX or LONG_MIN (as defined in
<limits.h>) is returned (according to the sign of the value), and errno is
set to ERANGE.
Otherwise, the long integer representation of str is returned.
ERRORS
[ERANGE] The correct value results in either an overflow or underflow.
RELATED INFORMATION
Functions: atoi(3), atof(3), atol(3), isspace(3), ctype(3), scanf(3),
strtod(3), strtoul(3)
2 Intergraph Corporation - 2/94