I am trying to match the input of a string by user with that of the string from a file. But there are two things that is not happening the right way.
typedef struct
{
int yyyy;
int mm;
int dd;
} Date;
int main()
{
FILE *fp2;
fp2=fopen("StudentId.txt","r");
char input[255];
char *id;
id = (char *)malloc(sizeof(Date));
printf("Enter your UserId:\n");
gets(id);
gets(id);
fgets(input,sizeof(input),fp2);
int cmp;
printf("%s_\n%s_\n",input,id );
return 0;
}
Firstly I have to use two gets(id) instead of one as the program seems to skip the first one. Second, the after getting stored is printed as follows
Aditya828
_Aditya828_
Which makes me wonder why is it storing input with a '\n' and id not. Is there any way to fix the issues?