回答
嘛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. 在關閉程序之前等待x秒鐘C++
- 4. 初始屏幕等待幾秒鐘
- 5. 如何在啓動淡出之前等待幾秒鐘啓動畫面?
- 6. jQuery .animate()無意中等待幾秒鐘後才執行
- 7. 硒等待幾秒鐘,然後運行下一行
- 8. 在表單提交之前等待3秒鐘JavaScript的
- 9. 等待幾秒鐘後再運行下一步量角器
- 10. 爲什麼nosetests在執行前等待兩秒鐘?
- 11. 第二次打開對話框之前必須等待幾分鐘
- 12. 試圖讓程序等待幾秒鐘,然後繼續在C#中使用Unity
- 13. 不能在javascript中等待幾毫秒
- 14. 在使用javascript打印之前是否可以更改符號?
- 15. 等3秒鐘之前功能
- 16. Moment.js總是給人 「幾秒鐘前」
- 17. Objective-c:當我按住幾秒鐘的按鍵時,是否可以彈出UIScrollView
- 18. 讓我們等待幾秒鐘後再返回
- 19. 提示用戶,等待幾秒鐘,然後結束程序?
- 20. EDSDK:錯誤,如果打開相機會話,等待幾秒鐘,並拍照
- 21. 等待幾秒鐘,然後在腳本上運行下一個任務package.jscon
- 22. 在進程退出之前是否可以從perl CGI進行打印?
- 23. 代碼等待幾分鐘來檢查條件是否爲真
- 24. 在繼續執行代碼之前等待0.5秒VB.net
- 25. 如何製作代碼在C#中等待幾毫秒?
- 26. 在運行程序中等待一秒鐘
- 27. 在完成處理之前是否可以在while循環中打印PHP?
- 28. Php,執行動作前等待5秒
- 29. runIt之前等5秒鐘(而不是點擊)?
- 30. tomcat在停止部署啓動過程中需要等待幾秒鐘?
我已經試過什麼都沒有,我是新的C所以我不知道我可以使用,如果有一個...只是想知道的所有命令命令等待一定的時間做別的事情 – AppleAssassin