home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / func / atol.h next >
Encoding:
Text File  |  1985-05-06  |  736 b   |  32 lines

  1. /*
  2.  * atol();
  3.  *
  4.  * The atol() function is commonly missing from most compilers.
  5.  * The complete source to a atol() is listed below.
  6.  * This fucntion was copied from 'C Programmer's Library'
  7.  *
  8.  * Spelling corrected, L. Paper, 5/6/85
  9.  */
  10.  
  11. long atol(s)
  12. char *s;
  13. {
  14.  
  15.         long value;
  16.         int minus;
  17.  
  18.         while(isspace(*s))
  19.             s++;
  20.                 if(*s == '-')
  21.                 {
  22.                         s++;
  23.                         minus = 1;
  24.                 }
  25.                 else
  26.                         minus = 0;
  27.                 value = 0;
  28.                 while(isdigit(*s))
  29.                         value = value * 10 + *s++ - '0';
  30.                 return (minus ? -value : value);
  31. }
  32.