c語言延時語句
#include
里面有一個Sleep()函數(注意首字母大寫)。
還有別的方法,個人覺得這個最簡單了,下面是我從MSDN給你找的關于這個函數的詳細資料
函數原形:
VOID Sleep( DWORD dwMilliseconds // sleep time
);
ParametersdwMilliseconds [in] Specifies the time, in milliseconds, for which to suspend execution. A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. A value of INFINITE causes an infinite delay. Return ValuesThis function does not return a value. ==========================================================
調用的話,你懂的,呵呵,希望能幫到你。
在C語言中,如何寫延時段
最笨的方法就是用for語0句嵌套延時,這種,時間不準確,比如:
void delay(int num)
{
while(num>0)
{
/*時間可以自己修改*/
for(int i=0;i<100000;i++)
for(int j=0;j<100000;j++)
{
}
}
還可以使用時間來定時,可以準確的進行延時。但比較麻煩。
空語句起到延時作用中的“延時”是什么意思
拖時間,明了吧?
有時候,要控制程序的執行速度,
就可以加空語句,比如重復20000次,只計數,沒有實際操作語句.
這樣,程序要運行循環計數,就會有停頓下來的感覺.特別是在
在比較老的機器上,效果很明顯哦.
由于不同CPU運算速度不同,這個延時表現也會有不同的.
特別是在寫一些控制臺(DOS)程序時,可能要讓使用者看清輸出結果,再往下執行,又不想使用者參與輸入,要程序自然停頓,就可以加空循環來起到延時作用.