#include #include #define BUFSIZE 101 char buf[BUFSIZE]; int bufp = 0; /* * deliver the next character to be considered * reading from the buffer if it contains a character * and calling getchar if the buffer is empty */ int getch(void) { return (bufp > 0) ? buf[--bufp] : getchar(); } /* remember the characters put back on the input */ void ungetch(int c) { if (bufp >= BUFSIZE) { printf("ungetch: too many characters\n"); } else { buf[bufp++] = c; } } void ungets(char s[]) { int l = strlen(s); while (l) { ungetch(s[--l]); } }