2 * Exercise 4-9. Our getch and ungetch do not handle a pushed-back EOF
3 * correctly. Decide what their properties ought to be if an EOF is pushed
4 * back, then implement your design.
6 * EOF is defined as -1, so we need to change the buffer from an array of
7 * chars to an array of ints. The functions are otherwise identical
13 #define MAXLEN 1000 /* max size of buffer */
23 while ((s[i++] = c = getch()) != EOF) {
35 int buf[BUFSIZE]; /* buffer for ungetch */
38 /* get a (possibly pushed back) character */
40 return (bufp > 0) ? buf[--bufp] : getchar();
43 /* push character back on input */
46 printf("ungetch: too many characters\n");
51 void ungets(char s[]) {