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
19

DESCRIPTION

21       The call atoi(str) shall be equivalent to:
22
23
24              (int) strtol(str, (char **)NULL, 10)
25
26       except that the handling of errors may differ. If the value  cannot  be
27       represented, the behavior is undefined.
28

RETURN VALUE

30       The  atoi()  function shall return the converted value if the value can
31       be represented.
32

ERRORS

34       No errors are defined.
35
36       The following sections are informative.
37

EXAMPLES

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

APPLICATION USAGE

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

RATIONALE

63       None.
64

FUTURE DIRECTIONS

66       None.
67

SEE ALSO

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