473,563 Members | 2,635 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 #1
19 3982
da*********@gma il.com said:
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?
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(N ULL), 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.program mer.win32
and comp.unix.progr ammer 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
Dec 24 '07 #2
On Dec 24, 10:34 am, 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

Regards,
Ivan Novick
http://www.0x4849.net
Dec 25 '07 #3
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.

--
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 25 '07 #4
In article <47************ ***@yahoo.com>,
CBFalconer <cb********@mai neline.netwrote :
>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.
Wanna bet?

No matter how many caveats he had included, someone (probably you or one
of your cabal) would still have had a go at it.

It's what we do here. The point is that at least one someone would have
found it too hard to resist. The egoboo, ya know...

Dec 25 '07 #5
"CBFalconer " <cb********@yah oo.comschrieb im Newsbeitrag
news:47******** *******@yahoo.c om...
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.
He did make it very clear that this is in the GNU C library. How could it
possibly get any clearer?

Bye, Jojo
Dec 26 '07 #6
Ivan Novick said:
On Dec 24, 10:34 am, 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?
No, I didn't write any of that. I merely quoted it. It was written by the
OP.
There is a sleep function in the GNU C library.
Yes. My reply (which you snipped) mentioned sleep().

--
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
Dec 26 '07 #7
"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
"CBFalconer " <cb********@yah oo.comschrieb im Newsbeitrag
news:47******** *******@yahoo.c om...
>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.
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

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 26 '07 #8
"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:
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.
http://www.gnu.org/software/libc/man...ng-Length.html
So what? Does that make strlen off topic here?

Bse, Jojo
Dec 26 '07 #9
Hey everybody,

I attempted to use the sleep() function, but I am using Pelles C
compiler and unistd.h has sleep() commented out. I guess I will have
to figure out something else to try to get my program to pause.

Thanks for your help everyone,

Dave
Dec 26 '07 #10

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

Similar topics

2
1415
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...
1
2151
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...
3
1861
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>...
10
5150
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
1667
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...
0
1105
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...
8
11389
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
3313
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
2377
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...
0
7659
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...
0
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
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...
0
6244
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...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
916
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...

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.