Blob
1 /*2 * Exercise 4-8. Suppose that there will never be more than one character of3 * pushback. Modify getch and ungetch accordingly.4 *5 */7 #include <stdio.h>8 #include <string.h>10 #define MAXLENGTH 80012 int getch(void);13 void ungetch(int c);15 #define BUFSIZE 10017 char buf = EOF; /* buffer for ungetch */19 /* get a (possibly pushed back) character, \0 if no character */20 int getch(void) {21 char c = bufp;22 bufp = EOF;23 return c;24 }26 /* push character back on input */27 void ungetch(int c) {28 if (bufp == EOF)29 bufp = c;30 else31 printf("ungetch: too many characters\n");32 }