...
The atoi()
, atol()
, and atoll()
functions convert the initial portion of a string token to int
, long int
, and long long int
representation, respectively. Except for the behavior on error, they are equivalent to
...
as follows:
Call | Equivalent on Success |
---|---|
|
|
...
|
...
|
...
|
...
|
|
...
|
...
|
...
|
...
|
|
...
|
...
|
...
|
...
Unfortunately, atoi()
and related functions lack a mechanism for reporting errors for invalid values. Specifically, the atoi()
, atol()
, and atoll()
functions
- do not need to set
errno
on an error - have undefined behavior if the value of the result cannot be represented (see undefined behavior 113 of Annex J of C99)
- return 0 if the string does not represent an integer, which is indistinguishable from a correctly formatted, zero-denoting input string.
...