simple_time.c: Remove unused variable
[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                 size_t len;
28                 time_t t = time(NULL);
29                 struct tm *tm = localtime(&t);
30
31                 str[0] = '\0';
32                 asctime_r(tm, str);
33                 len = strlen(str);
34                 printf("\r");
35                 strip_newlines(str);
36                 printf("%s", str);
37                 fflush(stdout);
38                 sleep(1);
39         }
40
41         return 0;
42 }