练习4-9 以上介绍的getch和ungetch函数不能正确地处理压回的EOF。考虑压回EOF时应如何处理?请实现你的方案。
#include <stdio.h>
#define BUFSIZE 10
#include "calc.h"char buf[BUFSIZE];
int bufp = 0;int getch(void)
{return (bufp > 0) ? buf[--bufp] : getchar();
}void ungetch(int c)
{if (bufp >= BUFSIZE)printf("ungetch: too many characters\n");else if (c != EOF)buf[bufp++] = c;return;
}