I have to make a project, where the user can see the student's fee records. He can also modify, delete and add a new record. But i am getting problem while running it. Anyone can please help me :(
here is my program
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
FILE *A, *B;
char another; int choice;
struct student
{
char name[40],f_name[40];int age,clas;long int rnum, fee;};
struct student s;
char stdname[40];
long int recsize;
A=fopen("fee.txt","rb+");
recsize=sizeof(s);
printf("1-Add new record \n 2-Display record \n 3-Edit record \n 4-delete record \n now enter your choice:- ");
scanf("%d",&choice);
switch(choice)
{case '1':
fseek(A,0,SEEK_END);
another='y';
do
{
printf("enter name , father name, age, class, roll num, fee");
scanf("%s %s %d %d %ld %ld", &s.name, &s.f_name, &s.age, &s.clas, &s.rnum, &s.fee);
fwrite(&s,recsize,1,A);
printf("Add another ? y/n");
scanf("%c",&another);
}
while(another=='y');
break;
case '2':
rewind(A);
while(fread(&s,recsize,1,A))
printf("\n %s %s %d %ld %ld", s.name,s.f_name,s.age,s.clas,s.rnum,s.fee);
break;
case 3:
do{
printf("\nenter the name of student to be modifief:");
scanf("%s",&stdname);
rewind(A);
while(fread(&s,recsize,1,A)==1)
{
if(strcmp(s.name, stdname)==0)
{
printf("enter new name, father name, age, class, roll num, fee:");
scanf("%s %s %d %d %ld %ld", &s.name, &s.f_name, &s.age, &s.clas, &s.rnum, &s.fee);
fseek(A,-recsize,SEEK_CUR);
fwrite(&s,recsize,1,A);
break;
}
}
printf(" modify anothe?");
fflush(stdin);
another=getche();
}
while(another=='y');
break;
case '4':
another='y';
while(another=='y')
{
printf("\nenter the name name of student whom you want to delete");
scanf("%s",&stdname);
B=fopen("tfee.tst","wb");
rewind(A);
while(fread(&s,recsize,1,A)==1)
{
if(strcmp(s.name,stdname)!=0)
fwrite(&s,recsize,1,A);}
fclose(A);
fclose(B);
remove("fee.txt");
rename("tfee.txt","fee.txt");
A=fopen("fee.txt","rb+");
printf("delete anothe");
fflush(stdin);
another=getche();
}
break;
case '0':
fclose(A);
exit(0);
}
return 0;
getch();
}
Thank you!