So this program receives some inputs from the user like name,age and city and write these to a file. It is intended to do so till the user inputs Y OR y, but after receiveing the first set of inputs it just ends..
Can anyone please sort it out ?
#include<stdio.h>
const char FILE_NAME[]="employee.dat";
struct emp
{
char name[40];
int age;
char city[30];
};
struct emp e;
int main()
{
FILE *fp;
char another;
fp=fopen(FILE_NAME,"w");
while(1)
{
printf("Enter name age and city of the employee\n");
scanf("%s%d%s",e.name,&e.age,e.city);
fprintf(fp,"%s\t%d\t%s\n\n",e.name,e.age,e.city);
printf("Do you want to enter another record\n");
fflush(stdin);
scanf("%c",&another);
if(another!='Y' || another!='y')
break;
}
return(0);
}
Question
LeviS LoVEr
So this program receives some inputs from the user like name,age and city and write these to a file. It is intended to do so till the user inputs Y OR y, but after receiveing the first set of inputs it just ends..
Can anyone please sort it out ?
#include<stdio.h> const char FILE_NAME[]="employee.dat"; struct emp { char name[40]; int age; char city[30]; }; struct emp e; int main() { FILE *fp; char another; fp=fopen(FILE_NAME,"w"); while(1) { printf("Enter name age and city of the employee\n"); scanf("%s%d%s",e.name,&e.age,e.city); fprintf(fp,"%s\t%d\t%s\n\n",e.name,e.age,e.city); printf("Do you want to enter another record\n"); fflush(stdin); scanf("%c",&another); if(another!='Y' || another!='y') break; } return(0); }Link to comment
Share on other sites
14 answers to this question
Recommended Posts