#include #include #include "calc.h" extern int getch(); extern void ungetch(); /* getop: get next operator or numeric operand */ int getop( char s[] ) { int i, c; while ((s[0] = c = getch()) == ' ' || c == '\t') ; s[1] = '\0'; if (!isdigit(c) && c != '.') return c; /* not a number */ i = 0; if (isdigit(c)) /* collect integer part */ while (isdigit(s[++i] = c = getch())) ; if (c == '.') /* collect fraction part */ while (isdigit(s[++i] = c = getch())) ; s[i] = '\0'; if (c != EOF) ungetch(c); return NUMBER; } int sgetop(char s[]) { int i, c; c=s[0]; if (!isdigit(c) && c != '.') return c; /* not a number */ i = 0; if (isdigit(c)) /* collect integer part */ while (isdigit(c=s[++i])) ; if (c == '.') /* collect fraction part */ while (isdigit(c=s[++i])) ; return NUMBER; }