#include<stdio.h>
#include<string.h>
typedef struct emp
{
char name[100];
int age;
}ee;
void main()
{
struct emp p;
FILE *ptr;
int i;
char ch[100];
ptr=fopen("ddd.txt","w+");
if(ptr==NULL)
{
printf("\n not able to open the file");
}
for(i=0;i<3;i++)
{
printf("Enter the name and the age");
fgets(p.name,100,stdin);
fflush(stdout);
scanf("%d",&p.age);
fprintf(ptr,"%s%d",p.name,p.age);
fflush(stdout);
}
fclose(ptr);
}
When i run the above code,on asking the second record, it does not ask for the age and the output "Enter the name and the age" comes directly. What is the reason for this and how can this be corrected??