The thing is to take 2 time stamps: one at the beginning and one at the end of the game. Then you subtract the beginning value from the end to get the elapsed time.
In terms of <time.h>
, you probably want to call clock()
to get these time stamps.
clock_t beginTime = clock();
And later:
clock_t endTime = clock();
double elapsed = (double)(endTime - beginTime) / CLOCKS_PER_SEC;
That would give you the time in seconds, which you could make into hours by dividing it further by 3600.
(Note: It's been a long time since I've programmed straight C so I may be off on something here? In C++, you would want to use std::chrono::steady_clock::now()
to get your time stamps, even though clock()
still exists.)