---
name: "atoi"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/atoi"
---

# atoi(3)

convert ASCII string to integer

## NAME

**atoi**, **atoi\_l** – convert ASCII string to integer

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<stdlib.h\>**

*int*\

**atoi**(*const char \*str*);

**#include \<xlocale.h\>**

*int*\

**atoi\_l**(*const char \*str*, *locale\_t loc*);

## DESCRIPTION

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)](/xlocale/3.md) 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.

## SEE ALSO

[atof(3)](/atof/3.md), [atol(3)](/atol/3.md), [strtod(3)](/strtod/3.md), [strtol(3)](/strtol/3.md), [strtoul(3)](/strtoul/3.md), [xlocale(3)](/xlocale/3.md)

## 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”).
