home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_04 / 1n04039a < prev    next >
Text File  |  1990-07-25  |  385b  |  36 lines

  1.  
  2. Listing 2
  3.  
  4. #include <ctype.h>
  5.  
  6. typedef int bool;
  7. #define FALSE 0
  8. #define TRUE 1
  9.  
  10. int atoi(const char *s)
  11.     {
  12.     int n = 0;
  13.     bool neg = FALSE;
  14.  
  15.     while (isspace(*s))
  16.         ++s;
  17.     if (*s == '+')
  18.         ++s;
  19.     else if (*s == '-')
  20.         {
  21.         neg = TRUE;
  22.         ++s;
  23.         }
  24.     while (isdigit(*s))
  25.         {
  26.         n = 10 * n + *s - '0';
  27.         ++s;
  28.         }
  29.     if (neg)
  30.         n = -n;
  31.     return n;
  32.     }
  33.  
  34. ----------
  35.  
  36.