Directions:

Write a program that asks the user for a date in the formatmm/dd/yyyy, using a custom struct to store the date informationentered in memory. The program should call a custom function thatadds seven days to the user’s date, passing in the data in and outof the custom function using the custom struct for the dates. Theprogram should then print out the original date entered and thedate one week late.

Anyway, here is the code, please check:

#include <stdio.h>

struct date//structure declaration
{
int day,month,year;//date,month,year;
};
void addseven(struct date d)//function which adds 7 to present dateand prints to stdout
{
int m[] ={31,28,31,30,31,30,31,31,30,31,30,31};//array to keeptrack of days in month

d.day = d.day+7;//incrementing days
if(d.day>m[d.month-1])//if exceeds monthly days limit then
{
int k=d.day-m[d.month-1];
d.day = k;
d.month = d.month+1;//increment month count
if(d.month>12)//if month exceeded 12
{
d.year =d.year+1;//incrementing year
d.month=1;
}

}

//printing result
printf(“Date after one week :%d/%d/%dn”,d.month,d.day,d.year);
}

int main()
{
struct date present;//present date

char c[10];
printf(“Enter date in format(mm/dd/yyyy) :”);

scanf(“%s”,c);//reading as string

int i=0,k=0,l,s=0;
for(i=0;c[i]!=’ ‘;i++)//converting to integer… and storing instructure
{

if(c[i]==’/’ && k==0)
{
k=1;
present.month = s;//storing month
s=0;
}
else if (c[i]==’/’ && k==1)
{
k=2;
present.day = s;//storing day
s=0;
}
else {
l = (int)c[i]-48;
s =s*10+l;}

}
present.year =s;//storing year

//printing present date
printf(“present date :%d/%d/%dn”,present.month,present.day,present.year);

addseven(present);//function calling

return 0;
}

I am having problems with this code crashing after I enter thedate although it compiles and runs. I know the program uses anappropriate struct for the date. Although the code includes acustom function that takes a custom struct for the date as aparameter, it does not return a struct with the instructionsindicate. Would it be better to have the function return theupdated struct instead of having the function print out the datewith 7 days added? I was thinking of using scanf(“%d/%d/%d”,&present.month, &present.day, &present.year);