getche() 函数定义在 conio.h 头文件中。它是一个字符输入函数,在用户从键盘按下任意键之前会保持输出屏幕,并且还会使用直接视频或 BIOS **回显**按下的字符。
int getche(void);
getche() 函数不带任何参数。它没有任何缓冲区来存储输入的字符。
getche() 函数返回键盘输入的字符作为输出。
| 输入 | 返回值 |
|---|---|
| 如果按键 | 按下的字符 |
#include <stdio.h>
#include <conio.h>
int main()
{
char value;
value = getche();
printf("Enter any character : \n");
printf("Entered character is : %c", value);
return 0;
}
输出
Enter any character : x Entered character is : x
#include <stdio.h>
#include <conio.h>
int main()
{
char ch;
printf(“Press any character: ”);
ch = getche();
printf(“\nPressed character is: %c”, ch);
}
输出
Press any character: a Pressed character is: a