getc()、getchar()、getch() 和 getche() 的区别
所有这些函数都用于从输入获取字符,并且每个函数都返回一个表示状态代码的整数。
以下是 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP