/* writing to the binary file */
#include"stdio.h"
main()
{
FILE *fp;
char another='Y';
struct emp
{
char name[40];
int age;
float bs;
};
struct emp e;
clrscr();
fp=fopen("emp.dat","ab+");
if(fp==NULL)
{
puts("cannot open file");
exit();
}
while(another=='Y')
{
printf("\Enter name,age & basic salary");
scanf("%s%d%f",e.name,&e.age,&e.bs);
fwrite(&e,sizeof(e),1,fp);
printf("Add another record (Y/N)");
fflush(stdin);
another=getche();
}
fclose(fp);
}
#include"stdio.h"
main()
{
FILE *fp;
char another='Y';
struct emp
{
char name[40];
int age;
float bs;
};
struct emp e;
clrscr();
fp=fopen("emp.dat","ab+");
if(fp==NULL)
{
puts("cannot open file");
exit();
}
while(another=='Y')
{
printf("\Enter name,age & basic salary");
scanf("%s%d%f",e.name,&e.age,&e.bs);
fwrite(&e,sizeof(e),1,fp);
printf("Add another record (Y/N)");
fflush(stdin);
another=getche();
}
fclose(fp);
}
No comments:
Post a Comment