回答
嘛sleep()
功能这么做,有几种方法来使用它;
在Linux上:
#include <stdio.h>
#include <unistd.h> // notice this! you need it!
int main(){
printf("Hello,");
sleep(5); // format is sleep(x); where x is # of seconds.
printf("World");
return 0;
}
和Windows您可以使用DOS.H或WINDOWS.H这样的:
#include <stdio.h>
#include <windows.h> // notice this! you need it! (windows)
int main(){
printf("Hello,");
Sleep(5); // format is Sleep(x); where x is # of milliseconds.
printf("World");
return 0;
}
,或者您可以使用DOS.H用于Linux的风格像睡眠所以:
#include <stdio.h>
#include <dos.h> // notice this! you need it! (windows)
int main(){
printf("Hello,");
sleep(5); // format is sleep(x); where x is # of seconds.
printf("World");
return 0;
}
这就是你如何睡在C和Windows上和Linux!对于Windows,这两种方法都应该可以工只需将参数#秒改为所需,然后插入任何需要暂停的地方,就像我之后的printf一样。 此外,注意:在使用WINDOWS.H时,请记得在睡眠首都S
,也那是它的毫秒! (感谢Chris指出了这一点)
之前,我也想指出来谁可以在此线程绊倒别人,记得把握睡眠(); !!!! – AppleAssassin
是的,否则编译时会出错。 – Annabelle
的东西不一样优雅的睡眠(),但使用标准库:
/* data declaration */
time_t start, end;
/* ... */
/* wait 2.5 seconds */
time(&start);
do time(&end); while(difftime(end, start) <= 2.5);
我将离开你的找出正确的头(#include
)为time_t
,time()
和difftime()
,和他们的意思。这是乐趣的一部分。 :-)
适用于所有OS
int main()
{
char* sent[5] ={"Hello ", "this ", "is ", "a ", "test."};
int i =0;
while(i < 5)
{
printf("%s", sent[i]);
int c =0, i++;
while(c++ < 1000000); // you can use sleep but for this you dont need #import
}
return 0;
}
- 1. 在执行某个功能之前让javascript等待几秒钟
- 2. 在硒中等待几秒钟?
- 3. 在Qt中等待几秒钟
- 4. Javascript - 在执行下一行之前等待5秒钟
- 5. 在执行代码之前让应用程序等待几秒钟?
- 6. 在关闭程序之前等待x秒钟C++
- 7. PHP - 等待几秒钟后继续?
- 8. 初始屏幕等待几秒钟
- 9. 如何在启动淡出之前等待几秒钟启动画面?
- 10. 我怎么才能让我的蜷曲在等待几秒钟之前刮呢?
- 11. 等待5秒钟
- 12. jQuery .animate()无意中等待几秒钟后才执行
- 13. 硒等待几秒钟,然后运行下一行
- 14. 在表单提交之前等待3秒钟JavaScript的
- 15. Windows窗体在显示消息之前等待5秒钟
- 16. 如何等待css3动画帧几秒钟并重新加载?
- 17. AngularJS:如何在输入框中输入后等待几秒钟
- 18. 碰撞后在循环中等待几秒钟
- 19. Linux中,如何等待几秒钟,在GDB
- 20. 展望等待几秒钟然后执行
- 21. 等待几秒钟而不会阻止UI执行
- 22. 等待几秒钟后再运行下一步量角器
- 23. 为什么nosetests在执行前等待两秒钟?
- 24. 试图让程序等待几秒钟,然后继续在C#中使用Unity
- 25. 第二次打开对话框之前必须等待几分钟
- 26. 在使用javascript打印之前是否可以更改符号?
- 27. 不能在javascript中等待几毫秒
- 28. 等3秒钟之前功能
- 29. 在检查mysql中的一行之前等待x秒
- 30. Moment.js总是给人 “几秒钟前”
我已经试过什么都没有,我是新的C所以我不知道我可以使用,如果有一个...只是想知道的所有命令命令等待一定的时间做别的事情 – AppleAssassin