1234567891011121314151617181920 |
- #include <stdio.h>
- #define BUFSIZE 100
- #define SIZE 16
- char buf[BUFSIZE]; /* buffer for ungetch */
- int bufp1 = 0; /* next free position in buf */
- int getch(void) /* get a (possibly pushed-back) character */
- {
- return (bufp1 > 0) ? buf[--bufp1] : getchar();
- }
- void ungetch(int c) /* push character back on input */
- {
- if (bufp1 >= BUFSIZE)
- printf("ungetch: too many characters\n");
- else
- buf[bufp1++] = c;
- }
|