int main()
{
student s1;
FILE *fp, *temp;
int j, rno, found = 0;
fp = fopen("mystudents.txt", "r");
temp = fopen("temp.txt", "w");
printf("Enter rollno to delete : ");
scanf("%d", &rno);
while (fscanf(fp, "%d %s %d %d %d %d", &s1.rno, s1.name, &s1.sub[0].mark, &s1.sub[1].mark, &s1.sub[2].mark, &s1.total))
{
if (s1.rno == rno)
{
found = 1;
}
else
{
fprintf(fp, "%d %s %d %d %d %d", s1.rno, s1.name, s1.sub[0].mark, s1.sub[1].mark, s1.sub[2].mark, s1.total);
}
}
fclose(fp);
fclose(temp);
if (found)
{
temp = fopen("temp.txt", "r");
fp = fopen("mystudents.txt", "w");
while (fscanf(fp, "%d %s %d %d %d %d", &s1.rno, s1.name, &s1.sub[0].mark, &s1.sub[1].mark, &s1.sub[2].mark, &s1.total))
{
fprintf(fp, "%d %s %d %d %d %d", s1.rno, s1.name, s1.sub[0].mark, s1.sub[1].mark, s1.sub[2].mark, s1.total);
}
fclose(fp);
fclose(temp);
}
else
{
printf("not found");
}
return 0;
}
What I have tried:
I think the program is way too much buggy . It's taking input from the user but not compiling it. If u have any other way to do this , pls consider sharing it also.
If u have any other way to do this , pls consider sharing it also.