让程序暂停 [英] Making a program pause

查看:68
本文介绍了让程序暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我非常喜欢使用C语言进行编程,所有我必须使用

到目前为止我已经有了教程。在网上找到了。在我的搜索中,

然而,我还没有找到解决我遇到的问题的方法。

理想情况下,我希望程序在执行前等待5分钟

剩下的代码。有没有办法让我可以使用time.h而且只需要

运行一个for循环,等待5分钟后继续下去

程序?


非常感谢专家给你的任何帮助。

另外,如果我有一个明显的解决方案,我会提前道歉

忽略了。


谢谢,


Dave

Hi everybody,

I am awfully new to programming in C and all I have had to work with
so far have been tutorials that I''ve found online. In my searching,
however, I have not found a solution to a problem I have been facing.
Ideally, I would like the program to wait 5 minutes before executing
the rest of the code. Is there some way that I can use time.h and just
run a for loop that waits until 5 minutes has passed to continue down
the program?

Any help that you experts could give would be greatly appreciated.
Also, I apologize in advance if there is an obvious solution I have
overlooked.

Thanks,

Dave

推荐答案

da*********@gmail.com 说:

大家好,


我非常喜欢用C语言编程,所有我必须使用

到目前为止是我在网上找到的教程。在我的搜索中,

然而,我还没有找到解决我遇到的问题的方法。

理想情况下,我希望程序在执行前等待5分钟

剩下的代码。有什么方法可以使用time.h而且只需要

运行一个for循环,等待5分钟后再继续下去

程序?
Hi everybody,

I am awfully new to programming in C and all I have had to work with
so far have been tutorials that I''ve found online. In my searching,
however, I have not found a solution to a problem I have been facing.
Ideally, I would like the program to wait 5 minutes before executing
the rest of the code. Is there some way that I can use time.h and just
run a for loop that waits until 5 minutes has passed to continue down
the program?



有*是*你可以在标准C中做到这一点,是的 - 但它不是很好

好​​方法。它会起作用,但它会是忙碌的。循环,占用宝贵的

处理时间。你这样做:


#include< stddef.h>

#include< time.h>


无效延迟(无符号int秒)

{

time_t start = time(NULL);

double diff = 0.0;


while(diff< seconds)

{

diff = difftime(time(NULL),start);

}


返回;

} / *延迟5秒,呼叫延迟(5)* /


但是,就像我说的那样,这不是一个很好的方法。不幸的是,它是标准C中可用的最佳方式。你的C实现很可能是

提供一个基本相同工作的库函数,除了

处理器将被释放以执行其他操作。例如,Win32

提供Sleep(),POSIX(?)提供sleep()和usleep()。如果你想要

来讨论这些函数,我建议分别为comp.os.ms-windows.programmer.win32

和comp.unix.programmer。
< br $>
-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

There *is* a way you can do that in standard C, yes - but it''s not a very
good way. It will work, but it will be a "busy" loop, taking up valuable
processing time. You do it like this:

#include <stddef.h>
#include <time.h>

void delay(unsigned int seconds)
{
time_t start = time(NULL);
double diff = 0.0;

while(diff < seconds)
{
diff = difftime(time(NULL), start);
}

return;
} /* to delay for five seconds, call delay(5) */

but, like I said, this is not a very good way to do it. Unfortunately, it''s
the best way available in standard C. Your C implementation is very likely
to provide a library function that can do basically the same job except
that the processor will be released to do other things. For example, Win32
provides Sleep(), and POSIX(?) provides sleep() and usleep(). If you want
to discuss such functions, I suggest comp.os.ms-windows.programmer.win32
and comp.unix.programmer respectively.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


12月24日上午10点34分,Richard Heathfield< r ... @ see.sig.invalidwrote:
On Dec 24, 10:34 am, Richard Heathfield <r...@see.sig.invalidwrote:

理想情况下,我希望程序在执行

其余代码之前等待5分钟。有什么方法可以使用time.h而且只需要

运行一个for循环,等待5分钟后再继续下去

程序?
Ideally, I would like the program to wait 5 minutes before executing
the rest of the code. Is there some way that I can use time.h and just
run a for loop that waits until 5 minutes has passed to continue down
the program?



GNU C库中有一个睡眠功能。

http://www.gnu.org/software/libc/man....html#睡觉


问候,

Ivan Novick
http://www.0x4849.net


Ivan Novick写道:
Ivan Novick wrote:

Richard Heathfield< r ... @ see.sig.invalidwrote:
Richard Heathfield <r...@see.sig.invalidwrote:

>>理想情况下,我希望程序在执行其余代码之前等待5分钟。有没有什么方法可以使用
time.h并运行一个for循环,等待5分钟后才能继续执行程序?
>>Ideally, I would like the program to wait 5 minutes before
executing the rest of the code. Is there some way that I can use
time.h and just run a for loop that waits until 5 minutes has
passed to continue down the program?



GNU C库中有一个睡眠功能。

http://www.gnu.org/software/libc/man....html#睡觉



GNU C不是ISO标准C.扩展在这里是偏离主题的。如果你说清楚了,那么

就没有异议了。


-

圣诞快乐,快乐的Hanukah,快乐新年

Joyeux Noel,Bonne Annee,Frohe Weihnachten

Chuck F(cinefalconer at maineline dot net)

< http://cffalconer .home.att.net>


-

通过 http://www.teranews.com

GNU C is not ISO standard C. Extensions are off-topic here. There
would have been no objection if you had made this clear.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee, Frohe Weihnachten
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com


这篇关于让程序暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆