home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 387b.lha / dice_v2.02 / lib / stdlib / atoi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  442 b   |  38 lines

  1.  
  2. /*
  3.  *  int ATOI(str)
  4.  *
  5.  *  (c)Copyright 1990, Matthew Dillon, All Rights Reserved
  6.  */
  7.  
  8. #include <stdlib.h>
  9.  
  10. long
  11. atol(str)
  12. const char *str;
  13. {
  14.     return(atoi(str));
  15. }
  16.  
  17. int
  18. atoi(str)
  19. const char *str;
  20. {
  21.     short neg = 0;
  22.     long v = 0;
  23.  
  24.     while (*str == ' ' || *str == '\t')
  25.     ++str;
  26.     if (*str == '-') {
  27.     neg = 1;
  28.     ++str;
  29.     }
  30.     while (*str >= '0' && *str <= '9')
  31.     v = v * 10 + *str++ - '0';
  32.     if (neg)
  33.     v = -v;
  34.     return(v);
  35. }
  36.  
  37.  
  38.