Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: referenced Annex J and improved formatting.

...

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

atoi(nptr)

(int)strtol(nptr,

...

(char

...

**)NULL,

...

10)

...

atol(nptr)

strtol(nptr,

...

(char

...

**)NULL,

...

10)

...

atoll(nptr)

strtoll(nptr,

...

(char

...

**)NULL,

...

10)

...

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.

...