Hi,
I just want a program to be in an infinite loop but only do part of the code once a certain amount of time has elapsed.
I've tried using clock() but can't get it to work. Is the clock reset everytime in a while() loop?
Here's my code so far. I try to print the "duration" everytime through the loop but it's always 0.000000000.
Code:#include <time.h> int i = 0; clock_t start, finish, current; double duration; int main(){ start = clock(); while(1){ duration = (double) (current - start) / CLOCKS_PER_SEC; printf("Time elapsed = %.10f\n", duration); if (duration >= 5){ printf("5 Seconds is UP\n"); } } return 0; }



LinkBack URL
About LinkBacks


