1ATOI(3) Linux Programmer's Manual ATOI(3)
2
3
4
6 atoi, atol, atoll - convert a string to an integer
7
9 #include <stdlib.h>
10
11 int atoi(const char *nptr);
12 long atol(const char *nptr);
13 long long atoll(const char *nptr);
14
15 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17 atoll():
18 _ISOC99_SOURCE ||
19 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
20
22 The atoi() function converts the initial portion of the string pointed
23 to by nptr to int. The behavior is the same as
24
25 strtol(nptr, NULL, 10);
26
27 except that atoi() does not detect errors.
28
29 The atol() and atoll() functions behave the same as atoi(), except that
30 they convert the initial portion of the string to their return type of
31 long or long long.
32
34 The converted value or 0 on error.
35
37 For an explanation of the terms used in this section, see at‐
38 tributes(7).
39
40 ┌────────────────────────┬───────────────┬────────────────┐
41 │Interface │ Attribute │ Value │
42 ├────────────────────────┼───────────────┼────────────────┤
43 │atoi(), atol(), atoll() │ Thread safety │ MT-Safe locale │
44 └────────────────────────┴───────────────┴────────────────┘
46 POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD. C89 and POSIX.1-1996
47 include the functions atoi() and atol() only.
48
50 POSIX.1 leaves the return value of atoi() on error unspecified. On
51 glibc, musl libc, and uClibc, 0 is returned on error.
52
54 errno is not set on error so there is no way to distinguish between 0
55 as an error and as the converted value. No checks for overflow or un‐
56 derflow are done. Only base-10 input can be converted. It is recom‐
57 mended to instead use the strtol() and strtoul() family of functions in
58 new programs.
59
61 atof(3), strtod(3), strtol(3), strtoul(3)
62
64 This page is part of release 5.10 of the Linux man-pages project. A
65 description of the project, information about reporting bugs, and the
66 latest version of this page, can be found at
67 https://www.kernel.org/doc/man-pages/.
68
69
70
71GNU 2020-08-13 ATOI(3)