/* get next integer from input into *pn */ int getint(int *pn) { int c, t, sign; while (isspace(c = getch())); if (!isdigit(c) && c != EOF && c != '+' && c != '-') { ungetch(c); return 0; } sign = (c == '-') ? -1 : 1; if (c == '+' || c == '-') { t = c; if (!isdigit(c = getch())) { ungetch(c); ungetch(t); return t; } } for (*pn = 0; isdigit(c); c = getch()) *pn = 10 * *pn + (c - '0'); *pn *= sign; if (c != EOF) ungetch(c); return c; } /* get next float from input into *pn */ int getfloat(float *pn) { int c, t, sign, pow; while (isspace(c = getch())); if (!isdigit(c) && c != EOF && c != '+' && c != '-' && c != '.') { ungetch(c); return 0; } sign = (c == '-') ? -1 : 1; if (c == '+' || c == '-') { t = c; if (!isdigit(c = getch())) { if (c != '.') { ungetch(c); ungetch(t); return t; } } } for (*pn = 0; isdigit(c); c = getch()) *pn = 10 * *pn + (c - '0'); if (c == '.') c = getch(); for (pow = 1; isdigit(c); c = getch(), pow *= 10) *pn = 10 * *pn + (c - '0'); *pn *= sign; *pn /= pow; if (c != EOF) ungetch(c); return c; }