char buf[BUFSIZ];// buffer for ungetch
int bufp = 0; // next free position in buf
int getch(void){
return (bufp > 0) ? buf[--bufp] : getchar();
}
void ungetch(int c){// push character back on input
if (bufp >= BUFSIZ) {
printf("ungetch : too many characters\n");
}
else{
buf[bufp ++] = c;
}
}
C语言实现getch()和ungetch()
最新推荐文章于 2022-12-11 22:13:53 发布