getc()、getchar()、getch() 和 getche() 函数之间的区别
javaobject oriented programmingprogramming更新于 2024/5/16 17:48:17
所有这些函数都用于从输入中获取字符,每个函数都返回一个表示状态代码的整数。
以下是 getc()、getchar()、getch() 和 getche() 函数之间的重要区别。
getc()
getc() 可以从任何流中读取字符。失败时返回 EOF。
语法
int getc(FILE *stream);
getchar()
getchar() 只能从标准输入中读取字符。
语法
int getchar();
getch()
getch() 可以从标准输入读取字符,但它不使用任何缓冲区,并且立即返回,而不等待按下回车键。
语法
int getch();
getche()
getche() 的行为类似于 getch(),因为它可以从标准输入读取字符,它不使用任何缓冲区,并且立即返回,而不等待按下回车键。唯一的区别是它也会打印字符。
语法
int getch();
示例
#include <stdio.h>
#include <conio.h>
int main() {
printf("%c", getc(stdin));
printf("%c", getchar());
printf("%c", getch());
printf("%c", getche());
return 0;
}
输出
A B C D EE
相关文章
有用资源
java 参考教程 - 该教程包含有关 java 的更多信息:https://www.cainiaomax.com/java/

