If you call tomorrow 7 times you will get next weeks date.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct date {
int day;
int month;
int year;
} date;
date date_tomorrow (date today);
date date_nextweek (date today );
int main() {
date today, tomorrow, next_week ;
int i;
printf("Enter today's date in the format: (month/day/year) ie: 12 31 2005\n");
scanf("%d %d %d", &today.month, &today.day, &today.year);
tomorrow = date_tomorrow( today );
printf("Tomorrow's date will be: \n\n%d/%d/%d\n", tomorrow.month, tomorrow.day, tomorrow.year);
next_week = date_nextweek( today );
printf("Next weeks's date will be: \n\n%d/%d/%d\n", next_week.month, next_week.day, next_week.year);
}
int is_leap_year( int year ) {
if ((year % 400) == 0)
return 1;
else if ((year % 100) == 0)
return 0;
else if ((year % 4) == 0)
return 1;
return 0;
}
date date_nextweek (date today ) {
int i;
for ( i = 0; i < 7 ; i++ )
today = date_tomorrow(today);
return today;
}
date date_tomorrow ( date today) {
date tomorrow = today;
tomorrow.month = today.month;
tomorrow.day++;
tomorrow.year = today.year;
int leap_year = is_leap_year( tomorrow.year );
if (today.month == 2) {
if ( ( tomorrow.day > 28 && ! leap_year ) || ( tomorrow.day > 29 && leap_year ) ) {
tomorrow.day = 1;
tomorrow.month ++;
}
} else if (today.month==4||today.month == 6|| today.month==9 ||today.month == 11) {
if (tomorrow.day > 30) {
tomorrow.day = 1;
tomorrow.month ++;
}
}
else {
if (tomorrow.day > 31) {
tomorrow.day = 1;
tomorrow.month ++;
}
}
if (tomorrow.month > 12) {
tomorrow.month = 1;
tomorrow.year ++;
}
return tomorrow;
}
Kurt