I have a question in #c.
the code print all time "error" .
I try to do debugging but i didnt succeeded. The code should not enter the condition and it does enter the condition. What is the problem?
the code is:
int main()
{
    char name[10];
    int number_cores = 0, size = 0, grade = 0;
    float avarge = 0.0, sum = 0.0;
    FILE* fp = NULL;
    FILE *fwrite = NULL;
    int i;
    fp = fopen("grades.txt", "r");
    if (fp)
    {
        printf("error");
        return 0;
    }
    fwrite = fopen("averages.txt", "w");
    if (fwrite)
    {
        printf("error");
        return 0;
    }
    while (!feof(fp))
    {
        fscanf(fp, "%s", name);
        fprintf(fwrite,"%s:", name);
        fscanf(fp,"%d", &number_cores);
        sum = 0, grade = 0;
        for (i = 0; i < number_cores; i++)
        {
            fscanf(fp, "%d", &grade);
            sum += grade;
        }
        avarge = (sum / number_cores);
        fprintf(fwrite, "%f\n",avarge);
    }
    fclose(fwrite);
    fclose(fp);
    return 0;
}
 
    