473,698 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making a program pause

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
Dec 24 '07
19 3997
"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
"Keith Thompson" <ks***@mib.orgs chrieb im Newsbeitrag
news:87******** ****@kvetch.smo v.org...
>"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
>>"CBFalconer " <cb********@yah oo.comschrieb im Newsbeitrag
news:47****** *********@yahoo .com...
Ivan Novick wrote:
[...]
>>>>There is a sleep function in the GNU C library.
>
http://www.gnu.org/software/libc/man....html#Sleeping

GNU C is not ISO standard C. Extensions are off-topic here. There
would have been no objection if you had made this clear.
He did make it very clear that this is in the GNU C library. How could it
possibly get any clearer?

The GNU C library also has a strlen function.
http://www.gnu.org/software/libc/man...ng-Length.html
So what? Does that make strlen off topic here?
Of course not.

Sorry, apparently I wasn't as clear as I thought I was. My point is
that saying that the GNU C library has a sleep function does not by
itself make it perfectly clear that the sleep function is
non-standard.

The GNU C library provides implementations of both sleep() and
strlen(). strlen() is topical here; sleep() is not (though a brief
mention of sleep() with a redirection to a more appropriate forum is
IMHO perfectly ok).

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 26 '07 #11
Joachim Schmitz wrote:
"Keith Thompson" <ks***@mib.orgs chrieb im Newsbeitrag
>"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
>>"CBFalconer " <cb********@yah oo.comschrieb im Newsbeitrag
Ivan Novick wrote:
Richard Heathfield <r...@see.sig.i nvalidwrote:
>
>Ideally, I would like the program to wait 5 minutes before
>executin g 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?
>
There is a sleep function in the GNU C library.
>
http://www.gnu.org/software/libc/man....html#Sleeping

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

He did make it very clear that this is in the GNU C library.
How could it possibly get any clearer?

The GNU C library also has a strlen function.

So what? Does that make strlen off topic here?
No. But 'sleep' is off-topic. Have you caught on to the
difference yet?

--
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

Dec 26 '07 #12
CBFalconer <cb********@yah oo.comwrote:
# Ivan Novick wrote:
# Richard Heathfield <r...@see.sig.i nvalidwrote:
# >
# >>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?
# >
# There is a sleep function in the GNU C library.
# >
# http://www.gnu.org/software/libc/man....html#Sleeping
#
# GNU C is not ISO standard C. Extensions are off-topic here. There
# would have been no objection if you had made this clear.

system("sleep 300");

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Raining down sulphur is like an endurance trial, man. Genocide is the
most exhausting activity one can engage in. Next to soccer.
Dec 26 '07 #13
SM Ryan <wy*****@tang o-sierra-oscar-foxtrot-tango.fake.orgw rites:
CBFalconer <cb********@yah oo.comwrote:
Ivan Novick wrote:
Richard Heathfield <r...@see.sig.i nvalidwrote:
>
>>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?
>
There is a sleep function in the GNU C library.
>
http://www.gnu.org/software/libc/man....html#Sleeping
GNU C is not ISO standard C. Extensions are off-topic here. There
would have been no objection if you had made this clear.

system("sleep 300");
This is, of course, portable only to systems that provide a command
called "sleep" that does what you expect it to do.

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 27 '07 #14
"CBFalconer " <cb********@yah oo.comschrieb im Newsbeitrag
news:47******** *******@yahoo.c om...
Joachim Schmitz wrote:
>"Keith Thompson" <ks***@mib.orgs chrieb im Newsbeitrag
>>"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
"CBFalcone r" <cb********@yah oo.comschrieb im Newsbeitrag
Ivan Novick wrote:
>Richard Heathfield <r...@see.sig.i nvalidwrote:
>>
>>Ideally , I would like the program to wait 5 minutes before
>>executi ng 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?
>>
>There is a sleep function in the GNU C library.
>>
>http://www.gnu.org/software/libc/man....html#Sleeping
>
GNU C is not ISO standard C. Extensions are off-topic here.
There would have been no objection if you had made this clear.

He did make it very clear that this is in the GNU C library.
How could it possibly get any clearer?

The GNU C library also has a strlen function.

So what? Does that make strlen off topic here?

No. But 'sleep' is off-topic. Have you caught on to the
difference yet?
Of course I do and did. I was only pointing out that Ivan clearly stated
where his sleep is from.
Nothing else.

Bye, Jojo
Dec 27 '07 #15
[snips]

On Wed, 26 Dec 2007 23:09:13 +0000, SM Ryan wrote:
system("sleep 300");
Wonder what effect that would have on systems:

a) That have no sleep command
b) That have a sleep, but the parameter is in minutes
c) That have a sleep, but the parameter is in milliseconds
d) That have a sleep, but the parameter is a resource or device ID and
sleep waits for the resource to become available

FWIW, Windows XP - arguably the most populous desktop OS - seems to have
no bundled sleep command.
Dec 30 '07 #16
Not sure what you mean by bundled but the Windows API has a Sleep() function
that has been available at least since Windows 95.

Regards
Chris Saunders

"Kelsey Bjarnason" <kb********@gma il.comwrote in message
news:ho******** ****@spanky.loc alhost.net...
[snips]

On Wed, 26 Dec 2007 23:09:13 +0000, SM Ryan wrote:
>system("slee p 300");

Wonder what effect that would have on systems:

a) That have no sleep command
b) That have a sleep, but the parameter is in minutes
c) That have a sleep, but the parameter is in milliseconds
d) That have a sleep, but the parameter is a resource or device ID and
sleep waits for the resource to become available

FWIW, Windows XP - arguably the most populous desktop OS - seems to have
no bundled sleep command.
Dec 31 '07 #17
"Chris Saunders" <ev**@mountainc able.netwrites:
"Kelsey Bjarnason" <kb********@gma il.comwrote in message
[...]
>FWIW, Windows XP - arguably the most populous desktop OS - seems to have
no bundled sleep command.

Not sure what you mean by bundled but the Windows API has a Sleep()
function that has been available at least since Windows 95.
Please don't top-post (corrected here).

A Sleep() function is not the same as a "sleep" command.

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 31 '07 #18
On Dec 30, 10:12*pm, Keith Thompson <ks...@mib.orgw rote:
"Chris Saunders" <e...@mountainc able.netwrites:
"Kelsey Bjarnason" <kbjarna...@gma il.comwrote in message
[...]
FWIW, Windows XP - arguably the most populous desktop OS - seems to have
no bundled sleep command.
Not sure what you mean by bundled but the Windows API has a Sleep()
function that has been available at least since Windows 95.

Please don't top-post (corrected here).

A Sleep() function is not the same as a "sleep" command.
Besides which, there is a major distinction between a sleep command
and a sleep function.
There is a sleep command on my Windows machine, because I wrote it.
But for most Windows systems, if you execute this code snippet:

system("sleep 300");

there won't be any 3 second pause.
Dec 31 '07 #19
[snips]

On Sun, 30 Dec 2007 23:17:10 -0500, Chris Saunders wrote:
Not sure what you mean by bundled but the Windows API has a Sleep() function
that has been available at least since Windows 95.
Context:

system("sleep 300");

Explain to us how to invoke the Sleep() function, in a standard XP box,
using the code above.

Oh, right, you don't. XP has no sleep command, exactly as I said.
Jan 2 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1420
by: Ryan Spencer | last post by:
Hello again Everyone, I spent a small amount of time recently writing a program that "blinks" text. I did it by first having a user input a string, sys.stdout.write-ing the string, then backing up judging by the number of characters the string has, re-stdout's over it with blank spaces (judged again by it's character count), and then backs up again in a never ending while loop. It keeps each blink .5 seconds spaced as well, and all in...
1
2157
by: dan | last post by:
I need help in figuring out what to do for this program, it is a program that reads book id, unit price, book purchased, book sold, book returned, and city(respectively). It is a control break program that prints a report for each city on a separate screen with a total, then at the end it has a grand total. It prints to the screen and an output file. Input file looks like (the char is the city) 200 1.40 30 13 1 B 201 7.50 13 ...
3
1869
by: Thomas Matthews | last post by:
Is there anything technically wrong with the code below? I compiled it with g++ 3.3.1 and it executes with no errors. I compiled it with bcc32 5.6 and it executes with "This program has performed an illegal operation." I am running this on Windows 98 platform. {If not, I'll post this issue to a Borland newsgroup.} #include <iostream> #include <fstream>
10
5161
by: Amit Nath | last post by:
Hi! I am running a C program and need to pause the program and change some of the variables. Is there any function that checks if there is a character in the Standard Input Buffer, else the program keeps on running. Can someone please help me on that. AN
0
1668
by: wayne hamilton | last post by:
I'm having a problem Interacting with Command Line programs. I can read and write anything I want as long as I don't have to interact with a process once it's started. Originally I had been calling 'test.bat' directly, and in the latest incarnation (below) I am starting up cmd.exe and then writing the commands I want to execute to the command line that way. My problem is that I need to know if a program is waiting for input. In my batch...
0
1108
by: FaroeIslander | last post by:
Hello all. I am currently working on a program in VB.NET where the user can run a "hidden" DOS program and as the program is running the user can see how many computations have been performed by the program. To do this i am "piping" information back and forth between DOS and VB.NET. I also want to make the user able to abort and/or pause the computations in DOS. My question is how i can abort/pause a running DOS program. The only way to...
8
11392
by: Lloydm | last post by:
I've used the command "pause" in batch files which works ok but I guess it's applied dirrently in c++. Using Dev C++ 4.0 and the following is my code #include<iostream> #include<iomanip> #include<cstdlib> #include<string> main(){
12
3327
by: greg | last post by:
Hi, Can anyone help me with the following issue: How can I pause the execution of a program until a given file is created (by another process) in a specified directory? Any ideas would be highly appreciated. Thanks!
4
2384
by: Break2 | last post by:
I am trying to write a simple program which asks a user to enter 5 integers after which the average will be computed and written to the screen. That simple. However I want to do it according to a standard I used before to write a program which asked a user to enter the current year and his birthyear after which the current age of the user was computed and written to the screen. I got some help with the second program from some of you, thanks...
0
8668
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.