Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions: Write a program that asks the user for a date in the format mm/dd/

ID: 3596603 • Letter: I

Question

Instructions:
Write a program that asks the user for a date in the format mm/dd/yyyy, using a custom struct to store the date information entered in memory. The program should call a custom function that adds seven days to the user's date, passing in the data in and out of the custom function using the custom struct for the dates. The program should then print out the original date entered and the date one week later. As always, be sure to format your C code correctly and include meaningful comments to explain what the code does and how it works.

code previously provided in response to same quesetion:

#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 date and prints to stdout
{
int m[] ={31,28,31,30,31,30,31,31,30,31,30,31};//array to keep track 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/%d ",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 in structure
{
  
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/%d ",present.month,present.day,present.year);
  
addseven(present);//function calling
  
return 0;
}

******The Issue*******
I have reached the final steps whereas I can enter the date, however the present date and date after 7 days produce the incorrect year. The MM/DD is correct: Enter Date:10/19/2017
Present Date:10/19/20141
Future Date (1 week):10/26/20141

Please assist. Using a different compiler (as prev suggested in response to this same issue) is NOT an option, this is in c::b

Explanation / Answer

I executed the code in code blocks. I found the where the error is, but not able find the reason for it, which is going when I'm executing the code in c::b. With other compiler it is working fine.

Coming to resolution for the code to work in c::b is, modify the for loop as follows:

Original: for(i=0;c[i]!='';i++)//converting to integer... and storing in structure

Modified:  for(i=0;i<sizeof(c);i++)//converting to integer... and storing in structure

This modification worked fine in c::b..