Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1.  
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. typedef struct ntime
  8. {
  9. char day;
  10. char month[10];
  11. short year;
  12.  
  13. }ntime;
  14. int transform(char* timein)
  15. {
  16. /*
  17. 1 - January 8
  18. 2 - February 9
  19. 3 - March 6
  20. 4 - April 6
  21. 5 - May 4
  22. 6 - June 5
  23. 7 - July 5
  24. 8 - August 7
  25. 9 - September 10
  26. 10 - October 8
  27. 11 - November 9
  28. 12 - December 9
  29. */
  30.  
  31. struct ntime t;
  32.  
  33. t.day = ((timein[0] - '0') * 10) + timein[1] - '0';
  34. if (t.day > 31) { t.day = -1; }
  35. t.month[0] = ((timein[2] - '0') * 10) + timein[3] - '0';
  36. if (t.month[0] > 12) { t.month[0] = -1; }
  37. t.year = ((timein[4] - '0') * 10) + timein[5] - '0';
  38. if (t.day > 30) { t.year += 1900; }
  39. else { t.year += 2000; }
  40.  
  41.  
  42. if (t.day != -1 && t.month != -1 && t.year != -1)
  43. {
  44. switch (t.month[0])
  45. {
  46. case 1:
  47. //January
  48. t.month[0] = 'J';
  49. t.month[1] = 'a';
  50. t.month[2] = 'n';
  51. t.month[3] = 'u';
  52. t.month[4] = 'a';
  53. t.month[5] = 'r';
  54. t.month[6] = 'y';
  55. t.month[7] = '\0';
  56. break;
  57. case 2:
  58. //February
  59. t.month[0] = 'F';
  60. t.month[1] = 'e';
  61. t.month[2] = 'b';
  62. t.month[3] = 'r';
  63. t.month[4] = 'u';
  64. t.month[5] = 'a';
  65. t.month[6] = 'r';
  66. t.month[7] = 'y';
  67. t.month[8] = '\0';
  68. break;
  69. case 3:
  70. t.month[0] = 'M';
  71. t.month[1] = 'a';
  72. t.month[2] = 'r';
  73. t.month[3] = 'c';
  74. t.month[4] = 'h';
  75. t.month[5] = '\0';
  76. break;
  77. case 4:
  78. t.month[0] = 'A';
  79. t.month[1] = 'p';
  80. t.month[2] = 'r';
  81. t.month[3] = 'i';
  82. t.month[4] = 'l';
  83. t.month[5] = '\0';
  84. break;
  85. case 5:
  86. t.month[0] = 'M';
  87. t.month[1] = 'a';
  88. t.month[2] = 'y';
  89. t.month[3] = '\0';
  90. break;
  91. case 6:
  92. t.month[0] = 'J';
  93. t.month[1] = 'u';
  94. t.month[2] = 'n';
  95. t.month[3] = 'e';
  96. t.month[4] = '\0';
  97. break;
  98. case 7:
  99. t.month[0] = 'J';
  100. t.month[1] = 'u';
  101. t.month[2] = 'l';
  102. t.month[3] = 'y';
  103. t.month[4] = '\0';
  104. break;
  105. case 8:
  106. t.month[0] = 'A';
  107. t.month[1] = 'u';
  108. t.month[2] = 'g';
  109. t.month[3] = 'u';
  110. t.month[4] = 's';
  111. t.month[5] = 't';
  112. t.month[6] = '\0';
  113. break;
  114. case 9:
  115. t.month[0] = 'S';
  116. t.month[1] = 'e';
  117. t.month[2] = 'p';
  118. t.month[3] = 't';
  119. t.month[4] = 'e';
  120. t.month[5] = 'm';
  121. t.month[6] = 'b';
  122. t.month[7] = 'e';
  123. t.month[8] = 'r';
  124. t.month[9] = '\0';
  125. break;
  126. case 10:
  127. t.month[0] = 'O';
  128. t.month[1] = 'c';
  129. t.month[2] = 't';
  130. t.month[3] = 'o';
  131. t.month[4] = 'b';
  132. t.month[5] = 'e';
  133. t.month[6] = 'r';
  134. t.month[7] = '\0';
  135. break;
  136. case 11:
  137. t.month[0] = 'N';
  138. t.month[1] = 'o';
  139. t.month[2] = 'v';
  140. t.month[3] = 'e';
  141. t.month[4] = 'm';
  142. t.month[5] = 'b';
  143. t.month[6] = 'e';
  144. t.month[7] = 'r';
  145. t.month[8] = '\0';
  146. break;
  147. case 12:
  148. t.month[0] = 'D';
  149. t.month[1] = 'e';
  150. t.month[2] = 'c';
  151. t.month[3] = 'e';
  152. t.month[4] = 'm';
  153. t.month[5] = 'b';
  154. t.month[6] = 'e';
  155. t.month[7] = 'r';
  156. t.month[8] = '\0';
  157. break;
  158.  
  159. default:
  160. t.month[0] = '-';
  161. t.month[1] = '1';
  162. t.month[2] = '\0';
  163.  
  164. }
  165. printf("day = %d\nmonth - %s\nyear = %d\n", t.day, t.month, t.year);
  166. }
  167.  
  168.  
  169.  
  170. return 1;
  171. }
  172.  
  173. int main()
  174. {
  175. char timein[6] = { '\0','\0','\0','\0','\0','\0' };
  176. scanf("%s", &timein);
  177.  
  178.  
  179. transform(timein);
  180.  
  181.  
  182.  
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement