.TH atoi() "" "" "General Function (libc)"
.PC "Convert ASCII strings to integers"
.B "#include <stdlib.h>"
\fBint atoi(\fIstring\^\fB) \fBchar *\fIstring\^\fB;\fR
.PP
.B atoi()
converts
.I string
into the binary representation of an integer.
.I string
may contain a leading sign
and any number of decimal digits.
.B atoi()
ignores leading blanks and tabs; it
stops scanning when it encounters any
non-numeral other than the leading sign,
and returns the resulting
.BR int .
.SH Example
The following demonstrates
.BR atoi() .
It takes a string typed at the terminal, turns it into an
integer, then prints that integer on the screen.
To exit, type
.BR <ctrl-C> .
.DM
#include <stdlib.h>
.DE
.DM
main()
{
	extern char *gets();
	extern int atoi();
	char string[64];
.DE
.DM
	for(;;) {
		printf("Enter numeric string: ");
		if(gets(string))
			printf("%d\en", atoi(string));
		else
			break;
	}
}
.DE
.SH "See Also"
.Xr libc libc
.br
\*(AS, \(sc7.10.1.2
.br
\*(PX Standard, \(sc8.1
.SH Notes
.B atoi
does not check to see if the number represented by
.I string
fits into an \fBint\fR.
It returns zero if you hand it a string that it cannot interpret.
