1STRTOUL(3) Library Functions Manual STRTOUL(3)
2
3
4
6 strtoul - convert a string to an unsigned long
7
9 #include <stdlib.h>
10 #include <limits.h>
11
12 unsigned long
13 strtoul(nptr, endptr, base)
14 char *nptr;
15 char **endptr;
16 int base;
17
19 The strtoul() function converts the string in nptr to an unsigned long
20 value. The conversion is done according to the given base, which must
21 be between 2 and 36 inclusive, or be the special value 0.
22
23 The string may begin with an arbitrary amount of white space (as deter‐
24 mined by isspace(3)) followed by a single optional `+' or `-' sign. If
25 base is zero or 16, the string may then include a `0x' prefix, and the
26 number will be read in base 16; otherwise, a zero base is taken as 10
27 (decimal) unless the next character is `0', in which case it is taken
28 as 8 (octal).
29
30 The remainder of the string is converted to an unsigned long value in
31 the obvious manner, stopping at the end of the string or at the first
32 character that does not produce a valid digit in the given base. (In
33 bases above 10, the letter `A' in either upper or lower case represents
34 10, `B' represents 11, and so forth, with `Z' representing 35.)
35
36 If endptr is non nil, strtoul() stores the address of the first invalid
37 character in *endptr . If there were no digits at all, however, str‐
38 toul() stores the original value of nptr in *endptr . (Thus, if *nptr
39 is not `\0' but **endptr is `\0' on return, the entire string was
40 valid.)
41
43 The strtoul() function returns either the result of the conversion or,
44 if there was a leading minus sign, the negation of the result of the
45 conversion, unless the original (non-negated) value would overflow; in
46 the latter case, strtoul() returns ULONG_MAX and sets the global vari‐
47 able errno to ERANGE .
48
50 [ERANGE] The given string was out of range; the value converted
51 has been clamped.
52
54 strtol(3)
55
57 The strtoul() function conforms to ANSI C X3.159-1989 (``ANSI C'').
58
60 Ignores the current locale.
61
62
63
644.4 Berkeley Distribution January 12, 1996 STRTOUL(3)