how can I get my program to wait for a second before it does the next command?
I tried
for(i=0; i<10000; i++) {}
but on a pentium 3/1000mhz it doesn't slow it down at all. surely there is a better way.
Printable View
how can I get my program to wait for a second before it does the next command?
I tried
for(i=0; i<10000; i++) {}
but on a pentium 3/1000mhz it doesn't slow it down at all. surely there is a better way.
what compiler?
microsoft vc++
you need to include stdlib.h
and call this function where you want it to wait
_sleep( numberofmillisecondsgoeshere );
thanks, I have 4 text books and tried to look for 'wait' or 'sleep' but couldn't find anything.
As you have MSVC, you may wish to wander down the WinAPI road;Quote:
Originally posted by phantom
thanks, I have 4 text books and tried to look for 'wait' or 'sleep' but couldn't find anything.
From MSDNCode:Sleep
The Sleep function suspends the execution of the current thread for a specified interval.
VOID Sleep(
DWORD dwMilliseconds // sleep time in milliseconds
);
Parameters
dwMilliseconds
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 Values
This function does not return a value.
Dont forget the <windows.h>
Not to the millisecond, but works with everthing.
PHP Code:
#include <time.h>
int wait(int SecondsToWait)
{
time_t TheTime = time(NULL);
while(time(NULL) - TheTime < SecondsToWait);
return 1;
}
cheers all, I'll try the differant ways and see what works best.
quick question for code monkey -> what's the reason for 'return 1'?
It may be a stupid question but i'm asking it anyway :)