simple_time.c: fix set-but-not-used warning
[cmccabe-bin] / simple_time.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <time.h>
4 #include <unistd.h>
5
6 /* Prints a time on a single line of the console.
7  * I wrote this app so that I could measure times by repeatedly pressing
8  * return.
9  *
10  * Colin McCabe
11  */
12 void strip_newlines(char *str)
13 {
14         size_t i;
15         size_t str_len = strlen(str);
16
17         for (i = 0; i < str_len; i++) {
18                 if (str[i] == '\n')
19                         str[i] = ' ';
20         }
21 }
22
23 int main(void)
24 {
25         while (1) {
26                 char str[27];
27                 time_t t = time(NULL);
28                 struct tm *tm = localtime(&t);
29
30                 str[0] = '\0';
31                 asctime_r(tm, str);
32                 printf("\r");
33                 strip_newlines(str);
34                 printf("%s", str);
35                 fflush(stdout);
36                 sleep(1);
37         }
38
39         return 0;
40 }