Is the below issue happening because of null character. 'Yes/No'. Please explain why.
First code
#include<stdio.h>
struct date{ char day[2]; char month[2]; char year[4];
}current_date;
void main(){
printf("Enter day: ");
scanf("%s",current_date.day);
printf("Enter month: ");
scanf("%s",current_date.month);
printf("Enter year: ");
scanf("%s",current_date.year);
printf("\nEntered date is:
%s/%s/%s",current_date.day,current_date.month,current_date.year)
}
Input:
If I enter 17,02,1998 respectively for each scan.
Output:
Entered date is: 17021998/021998/1998
Second code for the same input when I just change the array length in structure.
#include<stdio.h>
struct date{ char day[3]; char month[3]; char year[5];
}current_date;
Rest the whole code is same.
Output
Entered date is: 17/02/1998
Please explain me this. Thank you in advance!
0-terminatedchar-array. The0needs to go somewhere.\0character.