home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / cscop122.zip / GETOP.C < prev    next >
Text File  |  1996-05-01  |  718b  |  41 lines

  1. #include <stdio.h>
  2.  
  3. #define NUMBER '0'
  4. #define TOOBIG '9'
  5.  
  6. int getop(char *s, int lim)
  7. {
  8.   int i,c;
  9.  
  10.   while ((c = getc(stdin)) == ' ' || c == '\t' ||
  11.           c == '\n')
  12.     ;
  13.     
  14.   if (c != '.' && (c < '0' || c > '9'))
  15.     return(c);
  16.  
  17.   s[0] = c;
  18.   for (i=1; (c = getc(stdin)) >= '0' && c <= '9'; i++)
  19.     if (i < lim)
  20.       s[i] = c;
  21.   if (c == '.')
  22.   { if (i < lim)
  23.       s[i] = c;
  24.     for (i++; (c = getc(stdin)) >= '0' && c <= '9'; i++)
  25.       if (i < lim)
  26.         s[i] = c;
  27.   }
  28.   
  29.   if (i < lim)
  30.   { ungetc(c,stdin);
  31.     s[i] = '\0';
  32.     return(NUMBER);
  33.   }
  34.   else
  35.   { while (c != '\n' && c != EOF)
  36.       c = getc(stdin);
  37.     s[lim-1] = '\0';
  38.     return(TOOBIG);
  39.   }
  40. }
  41.