Category : C Source Code
Archive   : CSRC2.ZIP
Filename : ATOI.C

 
Output of file : ATOI.C contained in archive : CSRC2.ZIP
/*
* a t o i . c
*/

/*)LIBRARY
*/

#ifdef DOCUMENTATION

title atoi Convert Ascii to integer
index Convert string to integer

synopsis
.s.nf
int
atoi(p)
char *p;
.s.f
Description

Convert string to integer. No data checking is performed.
The conversion stops at the first non-integer. Leading
spaces, tabs, plus-signs and/or newlines are ignored.
The integer may be preceeded by a minus sign.

Bugs

#endif

#define EOS 0

int
atoi(string)
register char *string;
/*
* Convert string to integer.
*/
{
register int value;
register int c;
int signflag;

value = 0;
signflag = 0;
while ((c = *string++) != EOS) {
switch (c) {
case '-': /* Set sign flag and skip */
signflag++;
case '\n':
case '\t':
case ' ':
case '+':
break; /* Skip over these */

default:
goto breakout; /* Exit while loop on others */
}
}
breakout:
while ((c -= '0') >= 0 && c <= 9) {
value *= 10;
value += c;
c = *string++;
}
return ((signflag) ? (-value) : value);
}


  3 Responses to “Category : C Source Code
Archive   : CSRC2.ZIP
Filename : ATOI.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/