|
|
coherent
atoi() General Function atoi()
Convert ASCII strings to integers
iinntt aattooii(_s_t_r_i_n_g) cchhaarr *_s_t_r_i_n_g;
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 iinntt. It returns zero if you hand it a string that
it cannot interpret.
COHERENT Lexicon Page 1
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.