Here the if statement inside the while loop should return the matching GPA holders. like how many students got GPA 10, but instead, it returns the same value twice along with the other values.
input: name: a, total gpa: 10 name : b, total gpa: 10 name :c, total gpa: 10
output: abac
void findGPATenHolders(int size)
{
Student Student3[100];
FILE *fp;
fp = fopen("students.txt", "r");
if (fp == NULL)
{
printf("File not found \n"); // this will be printed if we change data.txt to data1.txt
}
else
{
printf("*********Total GPA Analysis********\n");
int i=0;
while (fscanf(fp, "%d %s %lf %lf %lf\n", &Student3[i].id, &Student3[i].name, &Student3[i].totalGPA, &Student3[i].hscGPA, &Student3[i].sscGPA) != EOF)
{ int j = 0;
printf("GPA %.2f Students:", (float)Student3[i].totalGPA);
if (Student3[j].totalGPA == Student3[i].totalGPA && j != i)
{
printf("%s\n", Student3[j].name);
}
else
{
printf("Not working");
}
i++;
j++;
}
}
fclose(fp);
}