timer / stopwatch program in C and ncurses
I wrote a timer program in C, but it's not too accurate. Any ideas on how to make it more accurate, like to 10 ms or 100 ms or so. It doesn't need to be too accurate, but the current one is only accurate to the nearest second or so and pausing may introduce more error.
Code:
#include <stdio.h> Oh, and it should stay mostly portable, but I only run Linux. I was thinking of using usleep to pause for certain time, but I feel that the commands in-between will gradually add time to it and make it inaccurate, so before doing that I'm asking for other methods. Thanks |
use gettimeofday, it uses a struct to store sec/msec
|
I decided to use clock_gettime as it is recommended over gettimeofday, but it still doesn't work quite right, I'll have to think this over a bit. Maybe the math is wrong.
Code:
#include <stdio.h> |
Alright, I think I got it, here's the final version.
Code:
#include <stdio.h> |
All times are GMT -5. The time now is 12:17 AM. |