making a timer

i'm working on a timer that counts down from a set number of time until zero. i just don't understand clock() or the CLOCKS_PER_SECOND macro. how would i make the timer count down from lets say 20 seconds?

i figure if CLOCKS_PER_SECOND is the number of clock() 's in a second, then a function to make it count down from 20 seconds would look like this:
1
2
3
4
    clock_t running_time;
    running_time = clock() / CLOCKS_PER_SEC * 20;

    return running_time;

clock() gets the amount of time since the program started, so to time something you could do something like this

1
2
3
4
5
clock_t previousTime = clock();

// run some code

int numSecondsPassed = ( clock() - previousTime ) / CLOCKS_PER_SEC;
Last edited on
alright thanks.
Topic archived. No new replies allowed.