回答
嘛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