hello

#include<stdio.h>
#include<stdlib.h>
typedef struct student{
int rno;
char name[20];
struct subject{
int scode;
char sname[20];
int mark;
}sub[3];
int total;
float per;
}student;
void create();
void display(){
student s1;
FILE *fp;
int j;
fp=fopen("my students.txt","r");
while(fread(&s1,sizeof(student),1,fp))
{
printf("\n %-5%-20s",s1.rno,s1.name);
for(j=0;j<3;j++)
{
printf("%4d",s1.sub[j].mark);
}
printf("%5d%7.2f",s1.total,s1.per);
}
}
void append(){
student *s;
FILE fp;
int n,i,j;
printf("\n Enter how many students you want");
scanf("%d",&n);
s=(student)calloc(n,sizeof(student));
fp=fopen("my students.txt","a");
for(i=0;i<n;i++){
s[i].total=0;
s[i].per=0;
printf("\n Enter roll number:");
scanf("%d",&s[i]);
fflush(stdin);
printf("\n enter name:");
scanf("%[^\n]s",s[i].name);
for(j=0;j<3;j++)
{
printf("\n Enter marks of subject:%d",j+1);
scanf("%d",&s[i].sub[j].mark);
s[i].total+=s[i].sub[j].mark;
}
s[i].per=s[i].total/3.0;
fwrite(&s[i],sizeof(student),1,fp);
}
fclose(fp);

}
void noof_records(){
student s1;
FILE *fp;
fp=fopen("my students.txt","r");
fseek(fp,0,SEEK_END);
int n=ftell(fp)/sizeof(student);
printf("\n\n NO of Records=%d",n);
fclose(fp);
}
void search(){
student s1;
FILE *fp;
int j,rno,found=0;
fp=fopen("my students.txt","r");
printf("\n Enter roll numbers to search:");
scanf("%d",&rno);
while(fread(&s1,sizeof(student),1,fp))
{
if(s1.rno==rno)
{
found=1;
printf("\n %-5%-20s",s1.rno,s1.name);
for(j=0;j<3;j++)
{
printf("%4d",s1.sub[j].mark);
}
printf("%5d%7.2f",s1.total,s1.per);
}
if(!found)
printf("\n Record not found");
}
fclose(fp);
}
void update(){
student s1;
FILE *fp,*fp1;
int j,rno,found=0;
fp=fopen("my students.txt","r");
fp1=fopen("temp.txt","w");
printf("\n Enter roll numbers to update:");
scanf("%d",&rno);
while(fread(&s1,sizeof(student),1,fp))
{
if(s1.rno==rno)
{
found=1;
fflush(stdin);
printf("\n enter name:");
scanf("%[^\n]s",s1.name);
for(j=0;j<3;j++)
{
printf("\n Enter marks of subject:%d",j+1);
scanf("%d",&s1.sub[j].mark);
s1.total+=s1.sub[j].mark;
}
s1.per=s1.total/3.0;
fwrite(&s1,sizeof(student),1,fp);
fclose(fp);
fclose(fp1);
if(found){
fp1=fopen("temp.txt","r");
fp=fopen("my students.txt","w");
while(fread(&s1,sizeof(student),1,fp)){
fwrite(&s1,sizeof(student),1,fp);
}
}
else
printf("\n Record is not found");
}

1 2 3 } fclose(fp); fclose(fp1);

}
void delete(){
student s1;
FILE *fp,*fp1;
int j,rno,found=0;
fp=fopen("my students.txt","r");
fp1=fopen("temp.txt","w");
printf("\n Enter roll numbers to Delete:");
scanf("%d",&rno);
while(fread(&s1,sizeof(student),1,fp))
{
if(s1.rno==rno)
{
found=1;
}
else
fwrite(&s1,sizeof(student),1,fp);
fclose(fp);
fclose(fp1);
if(found){
fp1=fopen("temp.txt","r");
fp=fopen("my students.txt","w");
while(fread(&s1,sizeof(student),1,fp)){
fwrite(&s1,sizeof(student),1,fp);
}
}
else
printf("\n Record is not found");

1 2 3 } fclose(fp); fclose(fp1);

}
int main(){
int ch;
do{
printf("\n1.create");
printf("\n2.display");
printf("\n3.Append");
printf("\n4.No of Records");
printf("\n5.Search");
printf("\n6.Update");
printf("\n7.Delete");
printf("\n0.Exit");
printf("\n Enter your choice:");
scanf("%d",&ch);
switch(ch){
case 1:
create();
break;
case 2:
display();
break;
case 3:
append();
break;
case 4:
noof_records();
break;
case 5:
search();
break;
case 6:
update();
break;
case 7:
delete();
break;
}
}
while(ch !=0);
return 0;
}