Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- typedef struct ntime
- {
- char day;
- char month[10];
- short year;
- }ntime;
- int transform(char* timein)
- {
- /*
- 1 - January 8
- 2 - February 9
- 3 - March 6
- 4 - April 6
- 5 - May 4
- 6 - June 5
- 7 - July 5
- 8 - August 7
- 9 - September 10
- 10 - October 8
- 11 - November 9
- 12 - December 9
- */
- struct ntime t;
- t.day = ((timein[0] - '0') * 10) + timein[1] - '0';
- if (t.day > 31) { t.day = -1; }
- t.month[0] = ((timein[2] - '0') * 10) + timein[3] - '0';
- if (t.month[0] > 12) { t.month[0] = -1; }
- t.year = ((timein[4] - '0') * 10) + timein[5] - '0';
- if (t.day > 30) { t.year += 1900; }
- else { t.year += 2000; }
- if (t.day != -1 && t.month != -1 && t.year != -1)
- {
- switch (t.month[0])
- {
- case 1:
- //January
- t.month[0] = 'J';
- t.month[1] = 'a';
- t.month[2] = 'n';
- t.month[3] = 'u';
- t.month[4] = 'a';
- t.month[5] = 'r';
- t.month[6] = 'y';
- t.month[7] = '\0';
- break;
- case 2:
- //February
- t.month[0] = 'F';
- t.month[1] = 'e';
- t.month[2] = 'b';
- t.month[3] = 'r';
- t.month[4] = 'u';
- t.month[5] = 'a';
- t.month[6] = 'r';
- t.month[7] = 'y';
- t.month[8] = '\0';
- break;
- case 3:
- t.month[0] = 'M';
- t.month[1] = 'a';
- t.month[2] = 'r';
- t.month[3] = 'c';
- t.month[4] = 'h';
- t.month[5] = '\0';
- break;
- case 4:
- t.month[0] = 'A';
- t.month[1] = 'p';
- t.month[2] = 'r';
- t.month[3] = 'i';
- t.month[4] = 'l';
- t.month[5] = '\0';
- break;
- case 5:
- t.month[0] = 'M';
- t.month[1] = 'a';
- t.month[2] = 'y';
- t.month[3] = '\0';
- break;
- case 6:
- t.month[0] = 'J';
- t.month[1] = 'u';
- t.month[2] = 'n';
- t.month[3] = 'e';
- t.month[4] = '\0';
- break;
- case 7:
- t.month[0] = 'J';
- t.month[1] = 'u';
- t.month[2] = 'l';
- t.month[3] = 'y';
- t.month[4] = '\0';
- break;
- case 8:
- t.month[0] = 'A';
- t.month[1] = 'u';
- t.month[2] = 'g';
- t.month[3] = 'u';
- t.month[4] = 's';
- t.month[5] = 't';
- t.month[6] = '\0';
- break;
- case 9:
- t.month[0] = 'S';
- t.month[1] = 'e';
- t.month[2] = 'p';
- t.month[3] = 't';
- t.month[4] = 'e';
- t.month[5] = 'm';
- t.month[6] = 'b';
- t.month[7] = 'e';
- t.month[8] = 'r';
- t.month[9] = '\0';
- break;
- case 10:
- t.month[0] = 'O';
- t.month[1] = 'c';
- t.month[2] = 't';
- t.month[3] = 'o';
- t.month[4] = 'b';
- t.month[5] = 'e';
- t.month[6] = 'r';
- t.month[7] = '\0';
- break;
- case 11:
- t.month[0] = 'N';
- t.month[1] = 'o';
- t.month[2] = 'v';
- t.month[3] = 'e';
- t.month[4] = 'm';
- t.month[5] = 'b';
- t.month[6] = 'e';
- t.month[7] = 'r';
- t.month[8] = '\0';
- break;
- case 12:
- t.month[0] = 'D';
- t.month[1] = 'e';
- t.month[2] = 'c';
- t.month[3] = 'e';
- t.month[4] = 'm';
- t.month[5] = 'b';
- t.month[6] = 'e';
- t.month[7] = 'r';
- t.month[8] = '\0';
- break;
- default:
- t.month[0] = '-';
- t.month[1] = '1';
- t.month[2] = '\0';
- }
- printf("day = %d\nmonth - %s\nyear = %d\n", t.day, t.month, t.year);
- }
- return 1;
- }
- int main()
- {
- char timein[6] = { '\0','\0','\0','\0','\0','\0' };
- scanf("%s", &timein);
- transform(timein);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement