1ATOI(3P)                   POSIX Programmer's Manual                  ATOI(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       atoi — convert a string to an integer
13

SYNOPSIS

15       #include <stdlib.h>
16
17       int atoi(const char *str);
18

DESCRIPTION

20       The functionality described on this reference page is aligned with  the
21       ISO C  standard.  Any  conflict between the requirements described here
22       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2017
23       defers to the ISO C standard.
24
25       The call atoi(str) shall be equivalent to:
26
27
28           (int) strtol(str, (char **)NULL, 10)
29
30       except  that  the handling of errors may differ. If the value cannot be
31       represented, the behavior is undefined.
32

RETURN VALUE

34       The atoi() function shall return the converted value if the  value  can
35       be represented.
36

ERRORS

38       No errors are defined.
39
40       The following sections are informative.
41

EXAMPLES

43   Converting an Argument
44       The  following example checks for proper usage of the program. If there
45       is an argument and the decimal conversion of  this  argument  (obtained
46       using atoi()) is greater than 0, then the program has a valid number of
47       minutes to wait for an event.
48
49
50           #include <stdlib.h>
51           #include <stdio.h>
52           ...
53           int minutes_to_event;
54           ...
55           if (argc < 2 || ((minutes_to_event = atoi (argv[1]))) <= 0) {
56              fprintf(stderr, "Usage: %s minutes\n", argv[0]); exit(1);
57           }
58           ...
59

APPLICATION USAGE

61       The atoi() function is subsumed by strtol() but is retained because  it
62       is  used extensively in existing code. If the number is not known to be
63       in range, strtol() should be used because atoi()  is  not  required  to
64       perform any error checking.
65

RATIONALE

67       None.
68

FUTURE DIRECTIONS

70       None.
71

SEE ALSO

73       strtol()
74
75       The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
76
78       Portions  of  this text are reprinted and reproduced in electronic form
79       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
80       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
81       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
82       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
83       event of any discrepancy between this version and the original IEEE and
84       The  Open Group Standard, the original IEEE and The Open Group Standard
85       is the referee document. The original Standard can be  obtained  online
86       at http://www.opengroup.org/unix/online.html .
87
88       Any  typographical  or  formatting  errors that appear in this page are
89       most likely to have been introduced during the conversion of the source
90       files  to  man page format. To report such errors, see https://www.ker
91       nel.org/doc/man-pages/reporting_bugs.html .
92
93
94
95IEEE/The Open Group                  2017                             ATOI(3P)
Impressum