1STRTOUL(3)                 Linux Programmer's Manual                STRTOUL(3)
2
3
4

NAME

6       strtoul, strtoull, strtouq - convert a string to an unsigned long inte‐
7       ger
8

SYNOPSIS

10       #include <stdlib.h>
11
12       unsigned long int strtoul(const char *nptr, char **endptr, int base);
13
14       unsigned long long int strtoull(const char *nptr, char **endptr,
15                                       int base);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       strtoull():
20           XOPEN_SOURCE >= 600 || _BSD_SOURCE || _SVID_SOURCE ||
21           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L;
22           or cc -std=c99
23

DESCRIPTION

25       The  strtoul() function converts the initial part of the string in nptr
26       to an unsigned long int value according to the given base,  which  must
27       be between 2 and 36 inclusive, or be the special value 0.
28
29       The string may begin with an arbitrary amount of white space (as deter‐
30       mined by isspace(3)) followed by a single optional '+' or '-' sign.  If
31       base  is zero or 16, the string may then include a "0x" prefix, and the
32       number will be read in base 16; otherwise, a zero base is taken  as  10
33       (decimal)  unless  the next character is '0', in which case it is taken
34       as 8 (octal).
35
36       The remainder of the string is converted to an unsigned long int  value
37       in  the  obvious manner, stopping at the first character which is not a
38       valid digit in the given base.  (In bases above 10, the letter  'A'  in
39       either  upper  or  lower  case represents 10, 'B' represents 11, and so
40       forth, with 'Z' representing 35.)
41
42       If endptr is not NULL,  strtoul()  stores  the  address  of  the  first
43       invalid  character  in  *endptr.   If there were no digits at all, str‐
44       toul() stores the original value of nptr in *endptr  (and  returns  0).
45       In particular, if *nptr is not '\0' but **endptr is '\0' on return, the
46       entire string is valid.
47
48       The strtoull() function works just  like  the  strtoul()  function  but
49       returns an unsigned long long int value.
50

RETURN VALUE

52       The  strtoul() function returns either the result of the conversion or,
53       if there was a leading minus sign, the negation of the  result  of  the
54       conversion  represented as an unsigned value, unless the original (non‐
55       negated) value would overflow; in the latter  case,  strtoul()  returns
56       ULONG_MAX  and sets errno to ERANGE.  Precisely the same holds for str‐
57       toull() (with ULLONG_MAX instead of ULONG_MAX).
58

ERRORS

60       EINVAL (not in C99) The given base contains an unsupported value.
61
62       ERANGE The resulting value was out of range.
63
64       The implementation may also set errno to EINVAL in case  no  conversion
65       was performed (no digits seen, and 0 returned).
66

CONFORMING TO

68       strtoul()  conforms to SVr4, C89, C99 and POSIX-2001, and strtoull() to
69       C99 and POSIX.1-2001.
70

NOTES

72       Since strtoul() can legitimately return 0 or ULONG_MAX (ULLONG_MAX  for
73       strtoull()) on both success and failure, the calling program should set
74       errno to 0 before the call, and then determine if an error occurred  by
75       checking whether errno has a nonzero value after the call.
76
77       In  locales  other  than the "C" locale, other strings may be accepted.
78       (For example, the thousands separator of the current locale may be sup‐
79       ported.)
80
81       BSD also has
82
83           u_quad_t strtouq(const char *nptr, char **endptr, int base);
84
85       with completely analogous definition.  Depending on the wordsize of the
86       current architecture, this may be equivalent to strtoull() or  to  str‐
87       toul().
88
89       Negative  values  are considered valid input and are silently converted
90       to the equivalent unsigned long int value.
91

EXAMPLE

93       See the example on the strtol(3) manual page; the use of the  functions
94       described in this manual page is similar.
95

SEE ALSO

97       atof(3), atoi(3), atol(3), strtod(3), strtol(3)
98

COLOPHON

100       This  page  is  part of release 3.53 of the Linux man-pages project.  A
101       description of the project, and information about reporting  bugs,  can
102       be found at http://www.kernel.org/doc/man-pages/.
103
104
105
106GNU                               2011-09-15                        STRTOUL(3)
Impressum