home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 223_01 / otoi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-12-31  |  640 b   |  19 lines

  1. #include stdio.h
  2. /*
  3. ** otoi -- convert unsigned octal string to integer nbr
  4. **          returns field size, else ERR on error
  5. */
  6.    static int xd,t;
  7.  
  8. otoi(octstr, nbr)  char *octstr;  int *nbr;  {
  9.   xd=0;
  10.   *nbr=0;
  11.   while((*octstr>='0')&(*octstr<='7')) {
  12.     t=*nbr;
  13.     t=(t<<3) + (*octstr++ - '0');
  14.     if ((t>=0)&(*nbr<0)) return ERR;
  15.     xd++; *nbr=t;
  16.     }
  17.   return xd;
  18.   }
  19.