Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (itiaax):

Can anyone tell me why this C read file is not working? *will give medal and fan*

OpenStudy (itiaax):

void class_rep() { FILE *studentdataPtr; studentdataPtr = fopen("studentdata.txt", "r"); if (studentdataPtr == NULL) { printf("There has been a file error."); exit(0); } else { printf("\n\n------------------------------------------------------------------------------------------------"); printf("\n\nROLL #\tName\t\t\tM\tG\tC\tG\tS\tBS\tAvg"); printf("\n\n------------------------------------------------------------------------------------------------"); for (student_counter=1; student_counter <= tot_students; student_counter++) { fscanf(studentdataPtr, "\n%2d\t%s\t\t\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f", &student_counter, s[student_counter].name, &s[student_counter].maths, &s[student_counter].grammar, &s[student_counter].composition, &s[student_counter].gen_studies, &s[student_counter].science, &s[student_counter].basic_span, &s[student_counter].student_average); printf("\n%2d\t%s\t\t\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f", student_counter, s[student_counter].name, s[student_counter].maths, s[student_counter].grammar, s[student_counter].composition, s[student_counter].gen_studies, s[student_counter].science, s[student_counter].basic_span, s[student_counter].student_average); } } fclose(studentdataPtr);

OpenStudy (itiaax):

When I run the program..nothing shows up except for the first two printf statements

OpenStudy (unklerhaukus):

``` :3:2: error: use of undeclared identifier 'FILE' FILE *studentdataPtr; ^ ```

OpenStudy (itiaax):

@UnkleRhaukus ..it's a snippet of my entire code..I already declared that file before in my write file (which I did not include)

OpenStudy (unklerhaukus):

well i dont know how to run you code without the FILE

OpenStudy (itiaax):

void store_stud_info() { FILE *studentdataPtr; studentdataPtr = fopen("studentdata.txt", "w"); if (studentdataPtr == NULL) { printf("There has been a file error."); } else { fprintf(studentdataPtr, "\n\n----------------------------------------------------------------------------------------------------------"); fprintf(studentdataPtr,"\n\nROLL #\tName\t\t\tM\tG\tC\tG\tS\tBS\tAvg"); for (student_counter=1; student_counter <= tot_students; student_counter++) { fprintf(studentdataPtr,"\n\n----------------------------------------------------------------------------------------------------------"); fprintf(studentdataPtr, "\n%2d\t%s\t\t\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f\t%4.1f", student_counter, s[student_counter].name, s[student_counter].maths, s[student_counter].grammar, s[student_counter].composition, s[student_counter].gen_studies, s[student_counter].science, s[student_counter].basic_span, s[student_counter].student_average); } } fclose(studentdataPtr); }

OpenStudy (itiaax):

There is the write file

OpenStudy (unklerhaukus):

sorry, i still can't get it to run (im still learning C)

OpenStudy (itiaax):

Okay, thanks nevertheless.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!