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

NAME

6       atoi - convert a string to an integer
7

SYNOPSIS

9       #include <stdlib.h>
10
11       int atoi(const char *str);
12
13

DESCRIPTION

15       The call atoi(str) shall be equivalent to:
16
17
18              (int) strtol(str, (char **)NULL, 10)
19
20       except  that  the handling of errors may differ. If the value cannot be
21       represented, the behavior is undefined.
22

RETURN VALUE

24       The atoi() function shall return the converted value if the  value  can
25       be represented.
26

ERRORS

28       No errors are defined.
29
30       The following sections are informative.
31

EXAMPLES

33   Converting an Argument
34       The  following example checks for proper usage of the program. If there
35       is an argument and the decimal conversion of  this  argument  (obtained
36       using atoi()) is greater than 0, then the program has a valid number of
37       minutes to wait for an event.
38
39
40              #include <stdlib.h>
41              #include <stdio.h>
42              ...
43              int minutes_to_event;
44              ...
45              if (argc < 2 || ((minutes_to_event = atoi (argv[1]))) <= 0) {
46                 fprintf(stderr, "Usage: %s minutes\n", argv[0]); exit(1);
47              }
48              ...
49

APPLICATION USAGE

51       The atoi() function is subsumed by strtol() but is retained because  it
52       is  used extensively in existing code. If the number is not known to be
53       in range, strtol() should be used because atoi()  is  not  required  to
54       perform any error checking.
55

RATIONALE

57       None.
58

FUTURE DIRECTIONS

60       None.
61

SEE ALSO

63       strtol()   ,  the  Base  Definitions  volume  of  IEEE Std 1003.1-2001,
64       <stdlib.h>
65
67       Portions of this text are reprinted and reproduced in  electronic  form
68       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
69       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
70       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
71       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
72       event of any discrepancy between this version and the original IEEE and
73       The Open Group Standard, the original IEEE and The Open Group  Standard
74       is  the  referee document. The original Standard can be obtained online
75       at http://www.opengroup.org/unix/online.html .
76
77
78
79IEEE/The Open Group                  2003                              ATOI(P)
Impressum