如何编写延时功能? [英] How to write a time delay function?
问题描述
您好,
我想写一个时间延迟功能,例如Timedelay(float time_lenth){}。
执行时,会延迟一些秒只要time_lenth
表示。你能帮忙写一下这样的功能吗?
----------------
可爱的新闻组
----------------
Hello,
I want to write a time delay function like "Timedelay(float time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth"
indicating. Could you help on how to write such a function?
----------------
lovely newsgroup
----------------
推荐答案
Chen Shusheng写道:
Chen Shusheng wrote:
你好,
我想写一个时间延迟函数,比如Timedelay(float time_lenth){} 。
当执行它时,只要time_lenth
指示就会延迟几秒钟。你能帮忙写一下这样的功能吗?
----------------
可爱的新闻组
----------------
Hello,
I want to write a time delay function like "Timedelay(float time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth"
indicating. Could you help on how to write such a function?
----------------
lovely newsgroup
----------------
usleep()是一种方法(而支持)。
usleep() is one way to do it ( whereas it is supported ).
陈树生说:
Chen Shusheng said:
您好,
我想编写一个时间延迟功能,如Timedelay(浮动
time_lenth){}。
执行时,会延迟几秒钟只要time_lenth
表示。你能帮忙写一下这样的功能吗?
Hello,
I want to write a time delay function like "Timedelay(float
time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth"
indicating. Could you help on how to write such a function?
#include< time.h>
void Timedelay(float time_lenth)
{
time_t start = time(NULL);
time_t end;
do
{
end = time(NULL);
} while(difftime(end,start)< time_lenth);
}
(大概是''lenth''在世界某个地方很有意义。)
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
#include <time.h>
void Timedelay(float time_lenth)
{
time_t start = time(NULL);
time_t end;
do
{
end = time(NULL);
} while(difftime(end, start) < time_lenth);
}
(Presumably ''lenth'' is meaningful somewhere in the world.)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
谢谢。
理查德希思菲尔德 < in ***** @ invalid.invalid>
??????:XY ******************** @ bt.com ...
Thanks.
"Richard Heathfield" <in*****@invalid.invalid>
??????:XY********************@bt.com...
陈树生说:
Chen Shusheng said:
>你好,
我想编写一个时间延迟函数,如Timedelay(float
time_lenth){}。
当执行它时,只要time_lenth指示它就会延迟几秒钟
。你能帮忙写一下这样的功能吗?
>Hello,
I want to write a time delay function like "Timedelay(float
time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth"
indicating. Could you help on how to write such a function?
#include< time.h>
void Timedelay(float time_lenth)
{
time_t start = time(NULL);
time_t end;
do
{
end = time(NULL);
} while(difftime(end,start)< time_lenth);
}
(大概是''lenth''在世界某个地方很有意义。)
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然是放弃www)
#include <time.h>
void Timedelay(float time_lenth)
{
time_t start = time(NULL);
time_t end;
do
{
end = time(NULL);
} while(difftime(end, start) < time_lenth);
}
(Presumably ''lenth'' is meaningful somewhere in the world.)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
这篇关于如何编写延时功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!