'\" 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 2023-03-30 "Linux man-pages 6.04" .SH NAME atoi, atol, atoll \- convert a string to an integer .SH LIBRARY Standard C library .RI ( libc ", " \-lc ) .SH SYNOPSIS .nf .B #include .PP .BI "int atoi(const char *" nptr ); .BI "long atol(const char *" nptr ); .BI "long long atoll(const char *" nptr ); .fi .PP .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE .PP .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 .PP .in +4n .EX strtol(nptr, NULL, 10); .EE .in .PP except that .BR atoi () does not detect errors. .PP 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). .ad l .nh .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ .BR atoi (), .BR atol (), .BR atoll () T} Thread safety MT-Safe locale .TE .hy .ad .sp 1 .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. .PP 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)