/* Name: Cameron Alston Section: CISP 400 / Fall 2007 Title: Date Validator Purpose: To convert a numerical date to a string if it is valid. SCR: 9/7/07 Analyzed problem, some C++ conversion. Alston 9/8/07 Finished conversion, andded string conversion, debugged, documented. Alston 9/12/07 Finalized program, documentation. Alston */ #include #include #include #include using namespace std; // String length definitions. #define MAXMONTH 15 #define MAXDAY 19 #define MAXYEAR 33 // Date structure. typedef struct { char month[MAXMONTH], day[MAXDAY], year[MAXYEAR]; }Date; // Functions. Date String_To_MDY(char * date_ptr, char dayOneStr[][8], char dayTeenStr[][12], char dayTenStr[][10], char yearThouStr[][17], char yearOneStr[][6], char yearTeenStr[][10], char yearTenStr[][8], char tempDay[], char tempYear[]); char * Strchcpy(char *T, char *S, int ch); // from S to T stops at ch // returns * to position after ch char* ConvertMonth(int convMonth); char* ConvertDay(int convDay, char dayOneStr[][8], char dayTeenStr[][12], char dayTenStr[][10], char yearTenStr[][8], char tempDay[]); char* ConvertYear(int convYear, char dayOneStr[][8], char yearThouStr[][17], char yearOneStr[][6], char yearTeenStr[][10], char yearTenStr[][8], char tempYear[]); int ValidateLeap(int numMonth, int numDay, int numYear); main() { // Arrays of date strings for conversion. char dayOneStr[9][8] = {"First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth"}; char dayTeenStr[9][12] = {"Eleventh", "Twelfth", "Thirteenth", "Fourteenth", "Fifteenth", "Sixteenth", "Seventeenth", "Eighteenth", "Nineteenth"}; char dayTenStr[3][10] = {"Tenth", "Twentieth", "Thirtieth"}; char yearThouStr[2][17] = {"Nineteen-Hundred", "Two-Thousand"}; char yearOneStr[9][6] = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; char yearTeenStr[9][10] = {"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}; char yearTenStr[9][8] = {"Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}; // Temporary variables for date cnversion. char tempDay[MAXDAY] = {'\0'}; char tempYear[MAXYEAR] = {'\0'}; // Main variables for input and display of data. char response[8]; char date_string [11]; Date mdy_date = {'\0'}; //User input prompt. cout << endl << "Do you want to convert and validate a date?(Y/N): "; cin >> response; // Validates input, prompts for date input. while (toupper(*response) == 'Y') { cout << endl << "Enter the date in mm/dd/yyyy form: "; cin >> date_string; fflush(stdin); // Call date conversion function. mdy_date = String_To_MDY(date_string, dayOneStr, dayTeenStr, dayTenStr, yearThouStr, yearOneStr, yearTeenStr, yearTenStr, tempDay, tempYear); // Display the data from the function. cout << "The converted date is the following: " << endl << endl; cout << "Month: " << setw(30) << mdy_date.month << endl; cout << "Day: " << setw(30) << mdy_date.day << endl; cout << "Year: " << setw(30) << mdy_date.year << endl; fflush(stdin); // Prompt for more input. cout << endl << "Do you want to convert and validate a date?(Y/N): "; cin >> response; } return 0; } /* End of main() */ Date String_To_MDY(char * date_ptr, char dayOneStr[][8], char dayTeenStr[][12], char dayTenStr[][10], char yearThouStr[][17], char yearOneStr[][6], char yearTeenStr[][10], char yearTenStr[][8], char tempDay[], char tempYear[]) { // Variables. Date mdy_date = {'\0'}; char month[3], day[3], year[5]; char * ch_ptr; int numDay, numMonth, numYear; // Uses a temp variables. ch_ptr = date_ptr; // Separates date_string into parts for month, day, and year. ch_ptr = Strchcpy(month, ch_ptr, '/'); ++ch_ptr; ch_ptr = Strchcpy(day, ch_ptr, '/'); ++ch_ptr; Strchcpy(year, ch_ptr, '\0'); // Temporary variables for leap year test. numMonth = atoi(month); numDay = atoi(day); numYear = atoi(year); // If the date is not Feb. 30, etc... if(ValidateLeap(numMonth, numDay, numYear)) { // Call functions that determines the string to represent the // numerical data and loads the string into the structure. strcat(mdy_date.month, ConvertMonth(atoi(month))); strcat(mdy_date.day, ConvertDay(atoi(day), dayOneStr, dayTeenStr, dayTenStr, yearTenStr, tempDay)); strcat(mdy_date.year, ConvertYear(atoi(year), dayOneStr, yearThouStr, yearOneStr, yearTeenStr, yearTenStr, tempYear)); // Sends the structure back to main for display. return mdy_date; } else { cout << endl << endl << "There are not that many days in February this year..." << endl; return mdy_date; } } /* End of String_To_MDY() */ char * Strchcpy(char * target, char * source, int ch) { // Tests for delimiter char. while (*source != ch && *source != '\0') { *target = *source; ++target; ++source; } // Inserts return char at end of string. *target = '\0'; return source; } /* End of Strchcpy() */ char* ConvertMonth(int convMonth) { // Returns the string for the month number. switch(convMonth) { case 1: return "January"; case 2: return "February"; case 3: return "March"; case 4: return "April"; case 5: return "May"; case 6: return "June"; case 7: return "July"; case 8: return "August"; case 9: return "September"; case 10: return "October"; case 11: return "November"; case 12: return "December"; default: return "Invalid Month"; } } char* ConvertDay(int convDay, char dayOneStr[][8], char dayTeenStr[][12], char dayTenStr[][10], char yearTenStr[][8], char tempDay[]) { int count; // Returns the string for the day number. switch(convDay / 10) { case 0: switch(convDay % 10) { case 1: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[0]); return tempDay; case 2: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[1]); return tempDay; case 3: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[2]); return tempDay; case 4: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[3]); return tempDay; case 5: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[4]); return tempDay; case 6: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[5]); return tempDay; case 7: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[6]); return tempDay; case 8: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[7]); return tempDay; case 9: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayOneStr[8]); return tempDay; } case 1: switch((convDay - 10)% 10) { case 0: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[0]); return tempDay; case 1: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[0]); return tempDay; case 2: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[1]); return tempDay; case 3: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[2]); return tempDay; case 4: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[3]); return tempDay; case 5: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[4]); return tempDay; case 6: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[5]); return tempDay; case 7: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[6]); return tempDay; case 8: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[7]); return tempDay; case 9: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTeenStr[8]); return tempDay; } case 2: switch((convDay - 20)% 10) { case 0: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); return tempDay; case 1: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[0]); return tempDay; case 2: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[1]); return tempDay; case 3: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[2]); return tempDay; case 4: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[3]); return tempDay; case 5: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[4]); return tempDay; case 6: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[5]); return tempDay; case 7: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[6]); return tempDay; case 8: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[7]); return tempDay; case 9: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[1]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[8]); return tempDay; } case 3: switch((convDay - 30) % 10) { case 0: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[2]); return tempDay; case 1: for(count = 0; count < MAXDAY; count ++) tempDay[count] = '\0'; strcat(tempDay, dayTenStr[2]); strcat(tempDay, "-"); strcat(tempDay, dayOneStr[0]); return tempDay; } default: return "Invalid Day"; } } char* ConvertYear(int convYear, char dayOneStr[][8], char yearThouStr[][17], char yearOneStr[][6], char yearTeenStr[][10], char yearTenStr[][8], char tempYear[]) { int count; // Returns the string for the year number. switch(convYear / 1000) { case 1: switch((convYear - 1900) / 10) { case 0: switch((convYear - 1900) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[8]); return tempYear; } case 1: switch((convYear - 1910) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[0]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTeenStr[8]); return tempYear; } case 2: switch((convYear - 1920) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[1]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[8]); return tempYear; } case 3: switch((convYear - 1930) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[2]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[8]); return tempYear; } case 4: switch((convYear - 1940) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[3]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[8]); return tempYear; } case 5: switch((convYear - 1950) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[4]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[8]); return tempYear; } case 6: switch((convYear - 1960) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[5]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[8]); return tempYear; } case 7: switch((convYear - 1970) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[6]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[8]); return tempYear; } case 8: switch((convYear - 1980) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[7]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[8]); return tempYear; } case 9: switch((convYear - 1990) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[6]); return tempYear; case 8: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[7]); return tempYear; case 9: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[0]); strcat(tempYear, " "); strcat(tempYear, yearTenStr[8]); strcat(tempYear, "-"); strcat(tempYear, yearOneStr[8]); return tempYear; } } case 2: switch((convYear - 2000) % 10) { case 0: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[1]); return tempYear; case 1: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[1]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[0]); return tempYear; case 2: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[1]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[1]); return tempYear; case 3: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[1]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[2]); return tempYear; case 4: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[1]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[3]); return tempYear; case 5: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[1]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[4]); return tempYear; case 6: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[1]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[5]); return tempYear; case 7: for(count = 0; count < MAXYEAR; count ++) tempYear[count] = '\0'; strcat(tempYear, yearThouStr[1]); strcat(tempYear, " "); strcat(tempYear, yearOneStr[6]); return tempYear; } default: return "Invalid Year"; } } int ValidateLeap(int numMonth, int numDay, int numYear) { // Check date against leap year days. if(numYear % 4 != 0 && numMonth == 2 && numDay > 28) return 0; else if(numYear % 4 == 0 && numMonth == 2 && numDay > 29) return 0; else return 1; }