'\" t .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Mon Mar 29 22:39:41 1993, David Metcalfe .\" Modified Sat Jul 24 21:38:42 1993, Rik Faith (faith@cs.unc.edu) .\" Modified Sun Dec 17 18:35:06 2000, Joseph S. Myers .\" .TH atoi 3 2024-05-02 "Linux man-pages 6.8" .SH NAME atoi, atol, atoll \- convert a string to an integer .SH LIBRARY Standard C library .RI ( libc ", " \-lc ) .SH SYNOPSIS .nf .B #include .P .BI "int atoi(const char *" nptr ); .BI "long atol(const char *" nptr ); .BI "long long atoll(const char *" nptr ); .fi .P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE .P .BR atoll (): .nf _ISOC99_SOURCE || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE .fi .SH DESCRIPTION The .BR atoi () function converts the initial portion of the string pointed to by \fInptr\fP to .IR int . The behavior is the same as .P .in +4n .EX strtol(nptr, NULL, 10); .EE .in .P except that .BR atoi () does not detect errors. .P The .BR atol () and .BR atoll () functions behave the same as .BR atoi (), except that they convert the initial portion of the string to their return type of \fIlong\fP or \fIlong long\fP. .SH RETURN VALUE The converted value or 0 on error. .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ .na .nh .BR atoi (), .BR atol (), .BR atoll () T} Thread safety MT-Safe locale .TE .SH VERSIONS POSIX.1 leaves the return value of .BR atoi () on error unspecified. On glibc, musl libc, and uClibc, 0 is returned on error. .SH STANDARDS C11, POSIX.1-2008. .SH HISTORY C99, POSIX.1-2001, SVr4, 4.3BSD. .P C89 and POSIX.1-1996 include the functions .BR atoi () and .BR atol () only. .\" .SH NOTES .\" Linux libc provided .\" .BR atoq () .\" as an obsolete name for .\" .BR atoll (); .\" .BR atoq () .\" is not provided by glibc. .\" The .\" .BR atoll () .\" function is present since glibc 2.0.2, but .\" not in libc4 or libc5. .SH BUGS .I errno is not set on error so there is no way to distinguish between 0 as an error and as the converted value. No checks for overflow or underflow are done. Only base-10 input can be converted. It is recommended to instead use the .BR strtol () and .BR strtoul () family of functions in new programs. .SH SEE ALSO .BR atof (3), .BR strtod (3), .BR strtol (3), .BR strtoul (3)