From d3b13f018be93d91da13ec029769be24280a319a Mon Sep 17 00:00:00 2001 From: Colin McCabe Date: Tue, 19 Jan 2010 15:15:36 -0800 Subject: [PATCH] Add simple_time.c app --- simple_time.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) create mode 100644 simple_time.c diff --git a/simple_time.c b/simple_time.c new file mode 100644 index 0000000..eea422f --- /dev/null +++ b/simple_time.c @@ -0,0 +1,41 @@ +#include +#include +#include + +/* Prints a time on a single line of the console. + * I wrote this app so that I could measure times by repeatedly pressing + * return. + * + * Colin McCabe + */ +void strip_newlines(char *str) +{ + size_t i; + size_t str_len = strlen(str); + + for (i = 0; i < str_len; i++) { + if (str[i] == '\n') + str[i] = ' '; + } +} + +int main(void) +{ + while (1) { + char str[27]; + size_t i, len; + time_t t = time(NULL); + struct tm *tm = localtime(&t); + + str[0] = '\0'; + asctime_r(tm, str); + len = strlen(str); + printf("\r"); + strip_newlines(str); + printf("%s", str); + fflush(stdout); + sleep(1); + } + + return 0; +} -- 1.6.6.rc1.39.g9a42