I have an increasing integer value and want to find the average per second of that integer. I am aware that timers do not exist in C unless you do something specific and complicated [Im new to C] Is there a simpler way to do this? Preferably the value would reset when the calculation is made in order to not have such a large number in memory as this application will be running for a long time.
Share
I think you will want to include
time.h, and use some of its functions and structs (this is actually not a bad way of learning the basics of C). There is an explanation and a few examples here.If you need sub-second accuracy I suggest you use
clock_gettime(), which will give you nanosecond resolution.Here is an example:
You will need to compile with something like:
The
-lrtpart of the command tells the C linker to link to the Realtime library, which contains the definition ofclock_gettime().