'\"macro stdmacro
.if n .pH g3c.strtol @(#)strtol	40.12 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} strtol 3C "C Programming Language Utilities" "\&"
.if \nX=1 .ds x} strtol 3C "C Programming Language Utilities"
.if \nX=2 .ds x} strtol 3C "" "\&"
.if \nX=3 .ds x} strtol "" "" "\&"
.TH \*(x}
.SH NAME
\f4strtol\f1, \f4strtoul\f1, \f4atol\f1, \f4atoi\f1 \- convert string to integer
.SH SYNOPSIS
\f4#include <stdlib.h>\f1
.PP
\f4long strtol (const char \(**str, char \(**\(**ptr, int base);\f1
.PP
\f4unsigned long strtoul (const char \(**str, char \(**\(**ptr, int base);\f1
.PP
\f4long atol (const char \(**str);\f1
.PP
\f4int atoi (const char \(**str);\f1
.SH DESCRIPTION
\f4strtol\fP
returns as a long integer the value represented by the character string
pointed to by
\f4str\fP.
The string is scanned up to the first
character inconsistent with the base.
Leading ``white-space'' characters
[as defined by
\f4isspace\fP
in
\f4ctype\fP(3C)]
are ignored.
.PP
If the value of
.I ptr\^
is not \f4(char \(**\(**)NULL\fP,
a pointer to the character terminating the scan is returned in
the location pointed to by
.IR ptr .
If no integer can be formed,
that location
is set to
\f4str\fP,
and zero is returned.
.PP
If
.I 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
.I base\^
is 16.
.PP
If
.I base\^
is zero, the string itself determines the base as follows: After an
optional leading sign a leading zero indicates octal conversion,
and a leading ``0x'' or ``0X'' hexadecimal conversion.  Otherwise,
decimal conversion is used.
.PP
Truncation from \f4long\fP to \f4int\fP can, of course, take place upon
assignment or by an explicit cast.
.PP
If the value represented by \f2str\fP would cause overflow,
\f4LONG_MAX\f1 or \f4LONG_MIN\f1 is returned
(according to the sign of the value), and
\f4errno\f1 is set to the value, \f4ERANGE\f1.
.PP
\f4strtoul\fP is similar to \f4strtol\fP except that \f4strtoul\f1 returns
as an unsigned long integer the value represented by \f2str\fP.
If the value represented by \f2str\fP would cause overflow,
\f4ULONG_MAX\f1 is returned, and
\f4errno\f1 is set to the value, \f4ERANGE\f1.
.PP
Except for behavior on error,
\f4atol(str)\fP
is equivalent to:
\f4strtol(str, (char \(**\(**)NULL, 10)\fP.
.PP
Except for behavior on error,
\f4atoi(str)\fP
is equivalent to:
\f4(int) strtol(str, (char \(**\(**)NULL, 10)\fP.
.SH DIAGNOSTICS
If \f4strtol\f1 is given a \f2base\f1 greater than 36,
it returns 0 and
sets \f4errno\f1 to \f4EINVAL\f1.
.SH SEE ALSO
\f4ctype\fP(3C), \f4scanf\fP(3S), \f4strtod\fP(3C).
.SH NOTES
\f4strtol\f1 no longer accepts values
greater than \f4LONG_MAX\f1 as valid input.
Use \f4strtoul\f1 instead.
.\"	@(#)strtol.3c	6.4 of 10/20/83
.Ee
