COHERENT manpages
This page displays the COHERENT manpage for atoi() [Convert ASCII strings to integers].
List of available manpages
Index
atoi() -- General Function (libc)
Convert ASCII strings to integers
#include <stdlib.h>
int atoi(string) char *string;
atoi() converts string into the binary representation of an integer.
string may contain a leading sign and any number of decimal digits. atoi()
ignores leading blanks and tabs; it stops scanning when it encounters any
non-numeral other than the leading sign, and returns the resulting int.
Example
The following demonstrates atoi(). It takes a string typed at the terminal,
turns it into an integer, then prints that integer on the screen. To exit,
type <ctrl-C>.
#include <stdlib.h>
main()
{
extern char *gets();
extern int atoi();
char string[64];
for(;;) {
printf("Enter numeric string: ");
if(gets(string))
printf("%d\n", atoi(string));
else
break;
}
}
See Also
libc
ANSI Standard, §7.10.1.2
POSIX Standard, §8.1
Notes
atoi does not check to see if the number represented by string fits into an
int. It returns zero if you hand it a string that it cannot interpret.











