OK I feel really stupid for this, but I can't get it to work. I thought you just needed #include<time.h> at the top to use it, but obviously not, so can anyone tell me what it should be instead of time.h please?
Printable View
OK I feel really stupid for this, but I can't get it to work. I thought you just needed #include<time.h> at the top to use it, but obviously not, so can anyone tell me what it should be instead of time.h please?
perhaps this?
Code:#include <ctime>
Code:void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
That is a very bad wait function consider what it is doing... you are putting it into an loop where it will be sucking up the processor hardcore. A better solution is Sleep/sleep, search it on the board to find a nice function that is crossplatform
You're right, Sleep(); is better. That's in milliseconds, right? So, Sleep(1000);
Yes, it's in milliseconds. Sleep(1000); is about 1 second. Make sure to:However, it's platform dependent!Code:#include <windows.h>
Oh and remember the uppercase issue with sleep().
In C it is:
sleep(1000);
In C++ it is:
Sleep(1000);
Very easy mistake to make
You're kidding, right?
C and C++ don't have sleep() as part of the standard.
I believe its Sleep() - the WinAPI, and sleep() - the windows.h function.
Sleep() - win32
sleep() - *nix
Or did our friend want this wait()...Code:void wait(size_t ms)
{
#ifdef WIN32
#include <windows.h>
Sleep(ms);
#else
#include <unistd.h>
usleep(ms);
#endif
}
I ... don't think it's a very good idea to include headers within functions.
Oh no, I really don't.
What happened to the xp_sleep functions I posted a few weeks back? The board can't find them, and neither can the other board at which I post regularly.