#include <stdlib.h>
unsigned long strtoul(const char *s, char **ep, int b);
unsigned long long strtoull(const char *s, char **ep, int b);
long strtol(const char *s, char **ep, int b);
long long strtoll(const char *s, char **ep, int b);
#include <inttypes.h>
uintmax_t strtoumax(const char *s, char **ep, int b);
intmax_t strtoimax(const char *s, char **ep, int b);
Functions with names matching ^str[a-z]
might be added to <stdlib.h>
.
#include <wchar.h>
unsigned long wcstoul(const wchar_t *s, wchar_t **ep, int b);
unsigned long long wcstoull(const wchar_t *s, wchar_t **ep, int b);
long wcstol(const wchar_t *s, wchar_t **ep, int b);
long long wcstoll(const wchar_t *s, wchar_t **ep, int b);
#include <inttypes.h>
uintmax_t wcstoumax(const wchar_t *s, wchar_t **ep, int b);
intmax_t wcstoimax(const wchar_t *s, wchar_t **ep, int b);
These functions parse an integer in base b
. After skipping initial white space, they
accept an optional sign +
or
-
, an optional type prefix
0x or 0X if b
is 16, and then one or more digits from the
first b
characters of the
following list, or their upper-case equivalents:
0123456789abcdefghijklmnopqrstuvwxyz
b
must be in the range 2 to 36,
or the special value 0. The special value indicates that
the base is to be chosen by the type prefix. If it is
0x or 0X, the base is taken to
be 16. If it is 0, the base is taken to be
8. Otherwise, the base is taken to be 10.
The functions return the converted number if it has
the expected form. If not, they return zero, and
*ep
is set to s
if ep
is not
NULL
. The *tou*
functions convert the result to an
unsigned value first. If the result overflows, each
function sets errno
to ERANGE
, and returns the largest
value of its return type, LONG_
, ULONG_
,
LLONG_
or
ULLONG_
.
#include <stdlib.h>
int atoi(const char *s);
long atol(const char *s);
long long atoll(const char *s);
atoi(s)
is equivalent to (int)
strtol(s, NULL, 10)
.
atol(s)
is equivalent to
strtol(s, NULL, 10)
.
atoll(s)
is equivalent to
strtoll(s, NULL, 10)
.