home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / word2x0a.zip / source / part_num_probe.c < prev    next >
C/C++ Source or Header  |  1998-04-20  |  668b  |  41 lines

  1. /* $Id: part_num_probe.c,v 1.1 1997/04/25 17:53:00 dps Exp $ */
  2. #include <ctype.h>
  3.  
  4. /* Find part number and return it or -1 if no number */
  5. int get_part_num(const char *st, const char *fence)
  6. {
  7.     int n;
  8.  
  9.     while (st<fence)
  10.     {
  11.     if (isspace(*st))
  12.     {
  13.         st++;
  14.         continue;
  15.     }
  16.     if (isdigit(*st))
  17.     {
  18.         n=0;
  19.         while (st<fence && isdigit(*st))
  20.         {
  21.         n=n*10+(*st)-'0';
  22.         st++;
  23.         }
  24.         if (!isspace(*st))
  25.         return -1;
  26.         else
  27.         return n;
  28.  
  29.     }
  30.     if (isupper(*st) && isspace(*(st+1)))
  31.         return (*st)-'A'+1;
  32.  
  33.     if (islower(*st) && isspace(*(st+1)))
  34.         return (*st)-'a'+1;
  35.  
  36.     /* Nothing else understood at this time */
  37.     return -1;
  38.     }
  39.     return -1;
  40. }
  41.