您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

在C语言中,kbhit指的是检测键盘是否有输入的函数

2024/3/11 16:22:02发布17次查看
在这里,我们将看到 c 中的 kbhit 功能。kbhit 基本上是键盘敲击。该函数位于 conio.h 头文件中。因此,为了使用它,我们必须将此头文件包含到我们的代码中。
kbhit() 的功能是,当按下某个键时,它返回非零值,否则返回零。
示例#include <stdio.h>#include <conio.h>main() { char ch; printf("enter keys (esc to exit)
"); while (1) { //define infinite loop for taking keys if (kbhit) { ch = getch(); // get typed character into ch if ((int)ch == 27) //when esc button is pressed, then it will comeout from loop break; printf("you have entered : %c
", ch); } }}
输出enter keys (esc to exit)you have entered : iyou have entered : tyou have entered : dyou have entered : wyou have entered : 5you have entered : /you have entered : *you have entered : +you have entered :you have entered : oyou have entered :you have entered : &
注意:这个 kbhit() 不是标准库。所以我们应该在代码中避免这种情况。
以上就是在c语言中,kbhit指的是检测键盘是否有输入的函数的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product