|
|
1.1 ! root 1: ! 2: ! 3: atoi() General Function atoi() ! 4: ! 5: ! 6: ! 7: ! 8: Convert ASCII strings to integers ! 9: ! 10: iinntt aattooii(_s_t_r_i_n_g) cchhaarr *_s_t_r_i_n_g; ! 11: ! 12: atoi converts string into the binary representation of an in- ! 13: teger. string may contain a leading sign and any number of ! 14: decimal digits. atoi ignores leading blanks and tabs; it stops ! 15: scanning when it encounters any non-numeral other than the ! 16: leading sign, and returns the resulting int. ! 17: ! 18: ***** Example ***** ! 19: ! 20: The following demonstrates atoi. It takes a string typed at the ! 21: terminal, turns it into an integer, then prints that integer on ! 22: the screen. To exit, type <ctrl-C>. ! 23: ! 24: ! 25: main() ! 26: { ! 27: extern char *gets(); ! 28: extern int atoi(); ! 29: char string[64]; ! 30: ! 31: ! 32: ! 33: for(;;) { ! 34: printf("Enter numeric string: "); ! 35: if(gets(string)) ! 36: printf("%d\n", atoi(string)); ! 37: else ! 38: break; ! 39: } ! 40: } ! 41: ! 42: ! 43: ***** See Also ***** ! 44: ! 45: atof(), atol(), general functions, int, printf(), scanf() ! 46: ! 47: ***** Notes ***** ! 48: ! 49: atoi does not check to see if the number represented by string ! 50: fits into an iinntt. It returns zero if you hand it a string that ! 51: it cannot interpret. ! 52: ! 53: ! 54: ! 55: ! 56: ! 57: ! 58: ! 59: ! 60: ! 61: ! 62: ! 63: ! 64: COHERENT Lexicon Page 1 ! 65: ! 66:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.