c - C - if 中的睡眠功能
问题描述
我使用 kbhit 函数处理一个快速时间事件,其中用户如果按下特定键会做一件事,否则会发生其他事情。我还想补充一点,如果用户在一段时间内没有点击那个键,程序就会进入 else。我写了这个,但它创建了一个循环。这是代码,如果你能帮我解决这个问题,那将是非常高兴的。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <unistd.h>
int main()
{
printf("\nYou approach him, you try to take him by the legs from behind.\n");
Sleep(1500);
while (!kbhit())
{
printf("PRESS C !!!\n");
int c = getch();
if ((c == 'c' || c == 'C') && sleep(3) != 0)
{
printf("Can you pick him up by the paws and\n");
break;
}
else if((c != 'c' || c != 'C') && sleep == 0) //damage 40
{
printf("\nYou failed to catch it and as it turns around it hurts you with its tail.\n");
getch();
break;
}
}
printf("Jhon takes out his Swiss Army knife and stabs him in the throat, killing him.\n");
}
解决方案
推荐阅读
- kubernetes - 访问路由器后面集群的 microk8s API
- pyspark - 对于 pyspark 数据帧,如何在一组 2 个有序列上添加行索引,以便为每个组重新启动行索引?
- python - 在 Abaqus 脚本中使用 Scipy
- charts - ChartJS 如何设置 x 轴刻度
- android - 添加新联系人时颤动contacts_service问题
- markdown - 更改使用 md 和 pandoc 生成的 pptx 中代码块的布局
- python - 如何从python运行cmd命令?
- reactjs - 使用三个力图和打字稿错误
- javascript - 在 Electron 应用中使用 Firebase 进行 Google 身份验证
- reactjs - 开始后不久,屏幕共享视频质量从原始质量下降到低质量