Originally Posted by
MK27
You can use a delay such as sleep(). While sleep() is not standard, I think it will be available in one form or another most places. On *nix, it uses seconds, which one letter a second is too slow, but you can instead use something with finer granularity such as nanosleep().
In the above mentioned game there was sleep() but my compiler gave the error message of "undefined rederence to 'sleep' ". So I looked up sleep in the faq and it said to use unistd.h, dos.h or windows.h , so i did and it still gave the same error message. In the faq it also said that sleep() is non-standard. Also covered in the faq was a sleep function :
Code:
#include <time.h>
void sleep_seconds ( long seconds ) {
clock_t limit, now = clock();
limit = now + seconds * CLOCKS_PER_SEC;
while ( limit > now )
now = clock();
}
void sleep_ticks ( long ticks ) {
clock_t limit, now = clock();
limit = now + ticks;
while ( limit > now )
now = clock();
}
void wait(long milliseconds)
{
long timeout = clock() + milliseconds;
while( clock() < timeout ) continue;
}
Is this the same as sleep() but portable?
Also is there a way I can use sleep() with my compiler? I use code::blocks minGW.