summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-10-26 02:10:26 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-10-26 02:10:26 +0000
commit2767024fce1a6afd8c8e300b47adbb477627a60d (patch)
tree864d33b1ba5feb8618cc6040139c7b9ef7661d13
parent7d5201f9672a2d41ca2846861e2b32e1099f2715 (diff)
replace time_print() with strtime()
-rw-r--r--textclock/textclock.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/textclock/textclock.c b/textclock/textclock.c
index dd48cfd..e10c616 100644
--- a/textclock/textclock.c
+++ b/textclock/textclock.c
@@ -16,6 +16,8 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <time.h>
char *approx[] = {
@@ -117,15 +119,21 @@ time_tod(int h, int m)
return tod[t];
}
-int
-time_print(FILE *fd, int h, int m)
+char *
+strtime(struct tm *now)
{
- return fprintf(fd,
- "The time is now, %s%s%s%s.\n",
+ char buf[80];
+ int h = now->tm_hour;
+ int m = now->tm_min;
+
+ snprintf(buf, sizeof(buf),
+ "The time is now, %s%s%s%s.",
time_approx(h, m),
time_min(h, m),
time_hour(h, m),
time_tod(h, m));
+
+ return strdup(buf);
}
int
@@ -133,12 +141,15 @@ main()
{
time_t t;
struct tm *tm;
+ char *s;
time(&t);
tm = localtime(&t);
+ s = strtime(tm);
fprintf(stdout, "Content-type: %s\r\n\r\n", "text/plain");
- time_print(stdout, tm->tm_hour, tm->tm_min);
+ fprintf(stdout, "%s\n", s);
+ free(s);
return 0;
}