Beginner in C here,
I can't seem to figure out what the problem here is. The display/search function goes into an infinite loop and does not stop even after I specify break at end-of-file. Can someone please tell me what is wrong here.
Code:
void display(FILE *fp)
{
printf("USN Name Marks1 Marks2 Marks3\n");
for(;;)
{
fscanf(fp,"%d%s%d%d%d",&st.usn,st.name,&st.marks1,&st.marks2,&st.marks3);
if(feof(fp)) \\what is wrong here??!
break;
printf("%-5d %-10s %-5d\t %-5d\t %-5d\n",st.usn,st.name,st.marks1,st.marks2,st.marks3);
}
}
int search(FILE *fp,int key)
{
for(;;)
{ fscanf(fp,"%d %s %d %d %d",&st.usn,&st.name,&st.marks1,&st.marks2,&st.marks3);
if(feof(fp))
break;
if(key==st.usn)
return 1;
}
return(0);
}