区别:https://www.geeksforgeeks.org/difference-getchar-getch-getc-getche/
int getc(FILE *stream);
标准库函数,头文件:stdio.h
功能:返回stream流的下一个字符,返回类型为unsigned char(被转换为int)。如果遇到文件结尾或发生错误,返回EOF。
利用getc()捕获字符时,字符会回显在屏幕上,且输入直到按下回车才结束,当stream是stdin时,和getchar()一样。
int getchar(void);
标准库函数,头文件:stdio.h
字符会回显在屏幕上,且输入直到按下回车才结束。等价于getc(stdin)
int ungetc(int c, FILE *stream);
标准库函数,头文件:stdio.h
功能:把 int 类型转换为 unsigned char 再写回到 stream 中,对每个流只能写回一个字符,且不能是EOF。
返回被写回的字符,如果出错则返回EOF。
int getch(void);
非标准库文件,头文件为:conio.h
功能:Gets a character from the console without echo(不带回显地从控制台获取一个字符),且不需要回车。
因为函数名不符合标准命名规则,建议使用 int _getch(void); 函数
int getche(void);
非标准库文件,头文件为:conio.h
功能:Gets a character from the console with echo(带回显地从控制台获取一个字符),且不需要回车。
因为函数名不符合标准命名规则,建议使用 int _getche(void); 函数
int ungetch(int c);
非标准库文件,头文件为:conio.h
The ungetch() function pushes c back onto the input queue until the next call to getch(). 将字符 c 退回到输入队列,直到下一次调用 getch() 取出。