atoi() General Function atoi() Convert ASCII strings to integers int atoi(string) char *string; atoi converts string into the binary representation of an in- teger. 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>. 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 ***** atof(), atol(), general functions, int, printf(), scanf() ***** 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. COHERENT Lexicon Page 1