/********************************************* This is a simple progrma to illustrate how to define a function that takes in an object as input and returns an object as output. *********************************************/ #include // note that the structure date is defined in // the header file. #include "increment_date.h" struct date increment_date(struct date d1) { struct date result; result = d1; // note that result = d1 is the same as the following three lines: //result.day = d1.day; //result.month = d1.month; //result.year = d1.year; result.day++; switch(result.month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (result.day == 32) { result.day = 1; result.month++; } break; case 2: if (result.day == 29) { result.day = 1; result.month++; } break; default: if (result.day == 30) { result.day = 1; result.month++; } } if (result.month == 13) { result.month = 1; result.year++; } return result; } int main(void) { /* date 1 */ struct date d1; d1.year = 2008; d1.month = 3; d1.day = 10; struct date d2 = increment_date(d1); printf("d1 = %d/%d/%d\n", d1.month, d1.day, d1.year); printf("d2 = %d/%d/%d\n", d2.month, d2.day, d2.year); }