Is there a way to make a loop execute for (let's say 5 seconds) and then break loop after the alotted time period is over?
Last edited on
Remember to:
#include <time.h>
Code:
1 2 3 4 5 6
|
clock_t started = clock();
while(started - clock < 5000)
{
//I suggest a sleep(1) here
}
| |
"clock()" returns the system time at the moment it was called, in ms.
Last edited on
And is there any way to repeat an instruction on periods (for instance from 5 in 5 seconds)?