複製鏈接
請複製以下鏈接發送給好友

ungetch

鎖定
ungetch的功能是把一個字符退回到鍵盤緩衝區中。
在較高版本的一些Visual Studio編譯器中(如vs2015),ungetch 被認為是不安全的,應當該使用 _ungetch 代替 ungetch 。
中文名
ungetch
性    質
函數名
用 法:
int ungetch(int c);
領    域
編程
函數名: ungetch
用 法:int ungetch(int c);
程序例:
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
int main( void )
{
    int i=0;
    char ch;
    puts("Input an integer followed by a char:");
    /* read chars until non digit or EOF */
    while((ch = getch()) != EOF && isdigit(ch))
        i = 10 * i + ch - 48; /* convert ASCII into int value */
    /* if non digit char was read, push it back into input buffer */
    if (ch != EOF)
        ungetch(ch);
    printf("\n\ni = %d, next char in buffer = %c\n", i, getch());
    return 0;
}