C语言实现getch()和ungetch()

来源:互联网 发布:oa软件是什么 编辑:程序博客网 时间:2024/05/16 11:21
 
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;      }    }

原创粉丝点击