2 5dc21454 2023-07-14 jrmu * Exercise 4-8. Suppose that there will never be more than one character of
3 5dc21454 2023-07-14 jrmu * pushback. Modify getch and ungetch accordingly.
7 5dc21454 2023-07-14 jrmu #include <stdio.h>
8 5dc21454 2023-07-14 jrmu #include <string.h>
10 5dc21454 2023-07-14 jrmu #define MAXLENGTH 800
12 5dc21454 2023-07-14 jrmu int getch(void);
13 5dc21454 2023-07-14 jrmu void ungetch(int c);
15 5dc21454 2023-07-14 jrmu #define BUFSIZE 100
17 5dc21454 2023-07-14 jrmu char buf = EOF; /* buffer for ungetch */
19 5dc21454 2023-07-14 jrmu /* get a (possibly pushed back) character, \0 if no character */
20 5dc21454 2023-07-14 jrmu int getch(void) {
21 5dc21454 2023-07-14 jrmu char c = bufp;
26 5dc21454 2023-07-14 jrmu /* push character back on input */
27 5dc21454 2023-07-14 jrmu void ungetch(int c) {
28 5dc21454 2023-07-14 jrmu if (bufp == EOF)
31 5dc21454 2023-07-14 jrmu printf("ungetch: too many characters\n");