- Joined
- Feb 19, 2022
- Messages
- 3
- Reaction score
- 0
I am working on a function that prints a calendar. I have another function that tells me if a year is a leap year. I have another function that tells me what day of the week that a month starts on. In this function I am having trouble getting the dates to change based on the start date. I can get either to work but not both. Small side note, if an array[] is empty it cant show 0 it has to be blank. Not sure how to do that part either.
Any help would be appreciated.
void print_calendar(int month, int year)
{
int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char *months[] = {"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"};
int first_day = day_of_the_week(1, month, year);
int array[35] = {0};
if(is_leapyear(year))
{
days_in_month[1] = 29;
}
array[first_day] = 1;
printf("%s, %i\n", months[month - 1], year);
printf("Su Mo Tu We Th Fr Sa\n");
printf("---------------------\n");
printf("%2d%3d%3d%3d%3d%3d%3d\n",array[0],array[1],array[2],array[3],array[4]
, array[5], array[6]);
}
Any help would be appreciated.
void print_calendar(int month, int year)
{
int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char *months[] = {"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"};
int first_day = day_of_the_week(1, month, year);
int array[35] = {0};
if(is_leapyear(year))
{
days_in_month[1] = 29;
}
array[first_day] = 1;
printf("%s, %i\n", months[month - 1], year);
printf("Su Mo Tu We Th Fr Sa\n");
printf("---------------------\n");
printf("%2d%3d%3d%3d%3d%3d%3d\n",array[0],array[1],array[2],array[3],array[4]
, array[5], array[6]);
}