1STRTOL(3)                  Library Functions Manual                  STRTOL(3)
2
3
4

NAME

6       strtol - convert string value to a long
7

SYNOPSIS

9       #include <stdlib.h>
10       #include <limits.h>
11
12       long
13       strtol(nptr, endptr, base)
14       char *nptr;
15       char **endptr;
16       int base;
17

DESCRIPTION

19       The strtol() function converts the string in nptr to a long value.  The
20       conversion is done according to the given base, which must be between 2
21       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 a long value in the obvious
31       manner,  stopping  at the first character which is not a valid digit in
32       the given base.  (In bases above 10, the letter `A' in either upper  or
33       lower  case  represents  10,  `B' represents 11, and so forth, with `Z'
34       representing 35.)
35
36       If endptr is non nil, strtol() stores the address of the first  invalid
37       character  in  *endptr .  If there were no digits at all, however, str‐
38       tol() stores the original value of nptr in *endptr.  (Thus, if *nptr is
39       not `\0' but **endptr is `\0' on return, the entire string was valid.)
40

RETURN VALUES

42       The  strtol() function returns the result of the conversion, unless the
43       value would underflow or overflow.  If an  underflow  occurs,  strtol()
44       returns  LONG_MIN.   If  an overflow occurs, strtol() returns LONG_MAX.
45       In both cases, errno is set to ERANGE .
46

ERRORS

48       [ERANGE]       The given string was out of range; the  value  converted
49                      has been clamped.
50

SEE ALSO

52       atof(3), atoi(3), atol(3), strtoul(3)
53

STANDARDS

55       The strtol() function conforms to ANSI C X3.159-1989 (``ANSI C'').
56

BUGS

58       Ignores the current locale.
59
60
61
624.4 Berkeley Distribution      January 12, 1996                      STRTOL(3)
Impressum