I created simple code to test the sleep() function. in C.
I execute the following code in attempts that the program waits 5 seconds before terminating:
#include <stdlib.h>
#include <stdio.h>
int main(){
int n=0;
for (n=1;n<=10;n++){
sleep(.5);
}
return 0;
}
It however waits about say 100ms. Well, definitely less than one second.
Now if I instead executed the following code:
#include <stdlib.h>
#include <stdio.h>
int main(){
int n=0;
for (n=1;n<=10;n++){
sleep(1);
}
return 0;
}
The program behaves as expected (waits 10 seconds before exiting).
Why does sleep() fail to execute properly when the parameter is a float?
and what's the absolute best function that's compatible with all systems that I can use in place of sleep?