【发布时间】:2020-06-01 19:27:39
【问题描述】:
我试图让 C 语言的函数 getch() 在 Windows 中只工作几秒钟。
#include <stdio.h>
#include <windows.h>
int main()
{
int v1, v2;
v1=getch();//I want this getch to only be activated for a few seconds
printf("Example");//That to activate the next function, even if the person reading this programm doesn't click in any key
return 0;
}
【问题讨论】:
-
你能让
stdin无缓冲吗? stackoverflow.com/questions/10247591/… -
@FiddlingBits 与 OP 的要求并不真正相关。
-
Windows - 你可以在超时循环中检查
kbhit()- 比如使用clock()。不需要特殊步骤,它是为您提供的,因此您不必提交阻塞功能 -
@MarcoBonelli 我不清楚。我的意思是您可以循环旋转并在时间到期时
break。getch(stdin) 的问题在于它默认会阻塞,对吧? -
@FiddlingBits 确切地说,它不是“默认情况下”,它只是在没有可用数据时阻止,就是这样。
标签: c windows codeblocks getch