fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void time_it(int hour, int minute);
  5. void say_hour(int hour);
  6. void say_min(int min);
  7.  
  8. int main(void) {
  9. char buffer[33];
  10. while (fgets(buffer, 33, stdin) != NULL) {
  11. int hour, minute;
  12. if (sscanf(buffer, "%d:%d", &hour, &minute) == 2) {
  13. time_it(hour, minute);
  14. }
  15. }
  16. return EXIT_SUCCESS;
  17. }
  18.  
  19. void time_it(int hour, int minute) {
  20. printf("It's ");
  21. say_hour(hour % 12);
  22. say_min(minute);
  23. if (hour >= 12)
  24. printf("pm\n");
  25. else
  26. printf("am\n");
  27. }
  28.  
  29. void say_min(int min) {
  30. switch (min) {
  31. case 0:
  32. break;
  33. case 1:
  34. printf("oh one ");
  35. break;
  36. case 2:
  37. printf("oh two ");
  38. break;
  39. case 3:
  40. printf("oh three ");
  41. break;
  42. case 4:
  43. printf("oh four ");
  44. break;
  45. case 5:
  46. printf("oh five ");
  47. break;
  48. case 6:
  49. printf("oh six ");
  50. break;
  51. case 7:
  52. printf("oh seven ");
  53. break;
  54. case 8:
  55. printf("oh eight ");
  56. break;
  57. case 9:
  58. printf("oh nine ");
  59. break;
  60. case 10:
  61. printf("ten ");
  62. break;
  63. case 11:
  64. printf("eleven ");
  65. break;
  66. case 12:
  67. printf("twelve ");
  68. break;
  69. case 13:
  70. printf("thirteen ");
  71. break;
  72. case 14:
  73. printf("fourteen ");
  74. break;
  75. case 15:
  76. printf("fifteen ");
  77. break;
  78. case 16:
  79. printf("sixteen ");
  80. break;
  81. case 17:
  82. printf("seventeen ");
  83. break;
  84. case 18:
  85. printf("eighteen ");
  86. break;
  87. case 19:
  88. printf("nineteen ");
  89. break;
  90. case 20:
  91. printf("twenty ");
  92. break;
  93. case 21:
  94. printf("twenty one ");
  95. break;
  96. case 22:
  97. printf("twenty two ");
  98. break;
  99. case 23:
  100. printf("twenty three ");
  101. break;
  102. case 24:
  103. printf("twenty four ");
  104. break;
  105. case 25:
  106. printf("twenty five ");
  107. break;
  108. case 26:
  109. printf("twenty six ");
  110. break;
  111. case 27:
  112. printf("twenty seven ");
  113. break;
  114. case 28:
  115. printf("twenty eight ");
  116. break;
  117. case 29:
  118. printf("twenty nine ");
  119. break;
  120. case 30:
  121. printf("thirty ");
  122. break;
  123. case 31:
  124. printf("thirty one ");
  125. break;
  126. case 32:
  127. printf("thirty two ");
  128. break;
  129. case 33:
  130. printf("thirty three ");
  131. break;
  132. case 34:
  133. printf("thirty four ");
  134. break;
  135. case 35:
  136. printf("thirty five ");
  137. break;
  138. case 36:
  139. printf("thirty six ");
  140. break;
  141. case 37:
  142. printf("thirty seven ");
  143. break;
  144. case 38:
  145. printf("thirty eight ");
  146. break;
  147. case 39:
  148. printf("thirty nine ");
  149. break;
  150. case 40:
  151. printf("forty ");
  152. break;
  153. case 41:
  154. printf("forty one ");
  155. break;
  156. case 42:
  157. printf("forty two ");
  158. break;
  159. case 43:
  160. printf("forty three ");
  161. break;
  162. case 44:
  163. printf("forty four ");
  164. break;
  165. case 45:
  166. printf("forty five ");
  167. break;
  168. case 46:
  169. printf("forty six ");
  170. break;
  171. case 47:
  172. printf("forty seven ");
  173. break;
  174. case 48:
  175. printf("forty eight ");
  176. break;
  177. case 49:
  178. printf("forty nine ");
  179. break;
  180. case 50:
  181. printf("fifty ");
  182. break;
  183. case 51:
  184. printf("fifty one ");
  185. break;
  186. case 52:
  187. printf("fifty two ");
  188. break;
  189. case 53:
  190. printf("fifty three ");
  191. break;
  192. case 54:
  193. printf("fifty four ");
  194. break;
  195. case 55:
  196. printf("fifty five ");
  197. break;
  198. case 56:
  199. printf("fifty six ");
  200. break;
  201. case 57:
  202. printf("fifty seven ");
  203. break;
  204. case 58:
  205. printf("fifty eight ");
  206. break;
  207. case 59:
  208. printf("fifty nine ");
  209. break;
  210. default:
  211. printf("ERROR ");
  212. break;
  213.  
  214. }
  215. }
  216.  
  217. void say_hour(int hour) {
  218. switch (hour) {
  219. case 0:
  220. printf("twelve ");
  221. break;
  222. case 1:
  223. printf("one ");
  224. break;
  225. case 2:
  226. printf("two ");
  227. break;
  228. case 3:
  229. printf("three ");
  230. break;
  231. case 4:
  232. printf("four ");
  233. break;
  234. case 5:
  235. printf("five ");
  236. break;
  237. case 6:
  238. printf("six ");
  239. break;
  240. case 7:
  241. printf("seven ");
  242. break;
  243. case 8:
  244. printf("eight ");
  245. break;
  246. case 9:
  247. printf("nine ");
  248. break;
  249. case 10:
  250. printf("ten ");
  251. break;
  252. case 11:
  253. printf("eleven ");
  254. break;
  255. default:
  256. printf("ERROR ");
  257. break;
  258. }
  259. }
Success #stdin #stdout 0s 9432KB
stdin
00:00
	01:30
	12:05
	14:01
	20:29
	21:00
stdout
It's twelve am
It's one thirty am
It's twelve oh five pm
It's two oh one pm
It's eight twenty nine pm
It's nine pm