atoi(3)

atoi3

Convert ascii string to integer

Usage

#include <stdlib.h>

int

atoi(const char *str);

#include <xlocale.h>

int

atoi_l(const char *str, locale_t loc);

Library

Standard C Library (libc, -lc)

Overview

The atoi() function converts the initial portion of the string pointed to by str to int representation.

It is equivalent to:

(int)strtol(str, (char **)NULL, 10);

While the atoi() function uses the current locale, the atoi_l() function may be passed a locale directly. See xlocale(3) for more information.

Implementation notes

The atoi() and atoi_l() functions are thread-safe and async-cancel-safe.

The strtol() and strtol_l() functions are recommended instead of atoi() and atoi_l() functions, especially in new code.

Errors

The function atoi() need not affect the value of errno on an error.

Releases

163 releases since Mac OS X 10.0; the text changed 5 times.

  1. 10.0–10.1.5
  2. 10.2–10.2.8
  3. 10.3–10.4.11
  4. 10.5–10.6.8
  5. 10.7–10.10.5
  6. 10.11–26.5

Standards

The atoi() function conforms to ISO/IEC 9945-1:1990 (“POSIX.1”), ISO/IEC 9899:1990 (“ISO C90”), and ISO/IEC 9899:1999 (“ISO C99”).

From Libc 1752.120.2 in macOS 26.5. Parsed by carta from the page's mdoc source.