Ok, for my Sunday homework I have to find the next day of the year using structures. Now, I can get the structure to read the entered date (tested that with a simple scanf to printf entered data), but I need to get it to be able to tell that it is the end of the month and print out the next month when necessary.
Here is what I got so far:
As you can see, I am trying to use an array for the max day of each month (excluding Leap Year for now).Code://Cameron Taylor #include <stdio.h> struct Date{ int month; int day; int year; }; int main(){ int max_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int i; struct Date next; printf("This program calculates the next day.\n"); printf("Please enter the current date in format dd/mm/yyyy: "); scanf("%d%*c%d%*c%d", &next.month, &next.day, &next.year); for (i = next.month-1; i < 12;) if (next.day = max_days[i]) next.month++; next.day = 1; printf("Tomorrows date is %d/%d/%d", next.month, next.day, next.year); return 0; }
Where I use the entered month to = 'i'. Then I use 'i' as the position in the array to see if next.day is = to the max day of that position of the array.
I am having no compiler issues with GCC using -w or -Wall, but after entering the current day the program stops working and doesn't go beyond the input.
commiedic@localhost Project18$ gcc -o -Wall Exercise4.c
commiedic@localhost Project18$ gcc -o -w Exercise4.c
commiedic@localhost Project18$ gcc -w Exercise4.c
commiedic@localhost Project18$ make Exercise4
make: `Exercise4' is up to date.
commiedic@localhost Project18$ make Exercise4
cc Exercise4.c -o Exercise4
commiedic@localhost Project18$ ./Exercise4
This program calculates the next day.
Please enter the current date in format dd/mm/yyyy: 07/21/2013
^C - Accidently hit ctrl+c to copy and it made the program quit, but usually it just sticks here.
commiedic@localhost Project18$