oops, you are right, the code I posted won't work for at least 2 or 3 different reasons 8o
Let's have a look at this one instead
static float time_in_seconds = 0;
static long prev_clock = 0;
long current_clock;
float time_diff;
current_clock = clock();
if (current_clock < prev_clock)
{
// calculate ticks elapsed up to rollover event
time_diff = LONG_MAX - prev_clock;
// add on ticks elapsed after rollover event
time_diff = time_diff + current_clock + 1;
}
else
time_diff = current_clock - prev_clock;
prev_clock = current_clock;
time_in_seconds += time_diff / CLOCKS_PER_SEC;
return time_in_seconds
Note
The function
MUST be called at least once between every rollover event!
DAMN! I still have no idea how to copy/paste code into this thing so it shows up the way I want it to. I need a tutorial or something.