0

İ am writing console game in C. I would like to measure how much time the user spends during the game until he or she loses or wins. Is there any library functions in C for this?

Emil
  • 73
  • 1
  • 12
  • `clock_gettime` is a high resolution function [with _nanosecond_ resolution] that I use quite a bit. Or, if you only need number of seconds, `time` is a bit simpler. – Craig Estey Oct 28 '18 at 19:04
  • How many do you want? There are lots, with different degrees of precision (one second — `time()` — to milliseconds (`ftime()`, to microseconds (`gettimeofday()`, down to nanosecond resolution — `clock_gettime()`), and different degrees of portability (some are available on just one system; some are available on most/all systems — that would be `time()`). Which platform are you working on? What resolution do you need? Are you looking at elapsed ('wall clock') time or CPU time or what? – Jonathan Leffler Oct 28 '18 at 19:09
  • I'm looking for 'wall clock' time and measuring time with seconds. Like how much time user spent on playing the game. I use IDE called Code::Blocks – Emil Oct 28 '18 at 19:13
  • You should tell us what library you are using, for example GLFW has it's own function for time, that automatically uses highest resolution clock possible on platform. But there's lots of others like SFML, and you don't even need them, you can create window manually so you can use other functions, it really depends. – Purple Ice Oct 28 '18 at 19:19
  • I want to use clock() function. It measures time for the execution process of the function in program. I do not know how to implement it for the all functions. – Emil Oct 28 '18 at 19:30
  • Possible duplicate of [How do I measure a time interval in C?](https://stackoverflow.com/questions/2150291/how-do-i-measure-a-time-interval-in-c) – anatolyg Oct 28 '18 at 21:29

0 Answers0