I am using this program to make a file(binary) and store some records in it.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
FILE *fp;
char another,str[20];
struct customer
{
int accno;
char c;
float balance;
};
struct customer e;
clrscr();
gets(str);
fp=fopen(str,"wb+");
if(fp==NULL)
{
puts("\nunable to open");
exit(1);
}
another='y';
while(another=='y')
{
printf("Enter accno.,name and balance:");
scanf("%d%c%f",&e.accno,&e.c,&e.balance);
fwrite(&e,sizeof(e),1,fp);
printf("Add another:");
fflush(stdin);
another=getche();
}
fclose(fp);
}
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
FILE *fp;
char another,str[20];
struct customer
{
int accno;
char c;
float balance;
};
struct customer e;
clrscr();
gets(str);
fp=fopen(str,"rb+");
if(fp==NULL)
{
puts("\nunable");
exit(1);
}
while(fread(&e,sizeof(e),1,fp)==1)
printf("\n%d %c %f",e.accno,e.c,e.balance);
fclose (fp);
}
Plz help me if you can.

