-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiw.c
110 lines (95 loc) · 2.18 KB
/
tiw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Written by Victor Zamanian <[email protected]> 2009 */
#ifndef TIMEINWORDS
#include "tiw.h"
#endif
char *singles[] = {
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine"
};
char *doubles[] = {
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen"
};
char *tens[] = {
"twenty",
"thirty",
"forty",
"fifty",
};
brokentime
getbrokentime (void)
{
time_t curtime = time (NULL);
return *localtime (&curtime);
}
char *
gettimestring (char *buffer)
{
brokentime bt = getbrokentime ();
char hour[20], min[20];
if (bt.tm_hour == 0) {
strcat (hour, doubles[2]);
} else if (bt.tm_hour < 10) {
strcat (hour, singles[bt.tm_hour-1]);
} else if (bt.tm_hour < 20) {
strcat (hour, doubles[bt.tm_hour - 10]);
} else {
strcat (hour, tens[bt.tm_hour / 10 - 2]);
if (bt.tm_hour % 10 > 0) {
strcat (hour, "-");
strcat (hour, singles[bt.tm_hour % 10 - 1]);
}
}
if (bt.tm_min == 0) {
strcat (min, "sharp");
} else if (bt.tm_min < 10) {
strcat ("oh-", singles[bt.tm_min - 1]);
} else if (bt.tm_min < 20) {
strcat (min, doubles[bt.tm_min - 10]);
} else {
strcat (min, tens[bt.tm_min / 10 - 2]);
if (bt.tm_min % 10 > 0) {
strcat (min, "-");
strcat (min, singles[bt.tm_min % 10 - 1]);
}
}
strcat (buffer, hour);
strcat (buffer, " ");
strcat (buffer, min);
return buffer;
}
int
main (void)
{
char string[50];
gettimestring (string);
printf("%s\n", string);
return 0;
}