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

NAME

6       atoi, atol, atoll - convert a string to an integer
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdlib.h>
13
14       int atoi(const char *nptr);
15       long atol(const char *nptr);
16       long long atoll(const char *nptr);
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       atoll():
21           _ISOC99_SOURCE
22               || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
23

DESCRIPTION

25       The  atoi() function converts the initial portion of the string pointed
26       to by nptr to int.  The behavior is the same as
27
28           strtol(nptr, NULL, 10);
29
30       except that atoi() does not detect errors.
31
32       The atol() and atoll() functions behave the same as atoi(), except that
33       they  convert the initial portion of the string to their return type of
34       long or long long.
35

RETURN VALUE

37       The converted value or 0 on error.
38

ATTRIBUTES

40       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
41       tributes(7).
42
43       ┌─────────────────────────────────────┬───────────────┬────────────────┐
44Interface                            Attribute     Value          
45       ├─────────────────────────────────────┼───────────────┼────────────────┤
46atoi(), atol(), atoll()              │ Thread safety │ MT-Safe locale │
47       └─────────────────────────────────────┴───────────────┴────────────────┘
48

VERSIONS

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

STANDARDS

54       C11, POSIX.1-2008.
55

HISTORY

57       C99, POSIX.1-2001, SVr4, 4.3BSD.
58
59       C89 and POSIX.1-1996 include the functions atoi() and atol() only.
60

BUGS

62       errno is not set on error so there is no way to distinguish  between  0
63       as  an error and as the converted value.  No checks for overflow or un‐
64       derflow are done.  Only base-10 input can be converted.  It  is  recom‐
65       mended to instead use the strtol() and strtoul() family of functions in
66       new programs.
67

SEE ALSO

69       atof(3), strtod(3), strtol(3), strtoul(3)
70
71
72
73Linux man-pages 6.04              2023-03-30                           atoi(3)
Impressum