gpt4 book ai didi

c - 双循环的 kbhit() 不能很好地工作

转载 作者:行者123 更新时间:2023-11-30 15:47:39 26 4
gpt4 key购买 nike

只是为了好玩,我尝试用循环打印 kbhit() ,以便在按键后程序无限打印该行,直到再次按下键盘。它编译得很好,运行时只会出现空白屏幕。没有打印品。但按一次按键就会结束程序。但控制台并未关闭。

#include <stdio.h>
#include <conio.h>

int main()
{
while(1)
{
if(kbhit())
{
while(1)
{
if(kbhit())
{
goto out;
}
printf("Print Ed Infinitum Until Key Press");
}
}
}
out:
return 0;
}

如何解决这个问题?

最佳答案

int main(void){
while(1){
if(kbhit()){
getch();
while(1){
if(kbhit()){
getch();
goto out;
}
printf("Print Ed Infinitum Until Key Press\n");
}
}
}
out:
return 0;
}

关于c - 双循环的 kbhit() 不能很好地工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17263037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com