I'm currently taking a C programming class over the summer right now. I'm using Visual Studio 2010. I really enjoy the class and am doing really well in it but I have a problem opening files in visual studio. I tried writing a program and I keep getting problems creating, opening files. I checked, double-checked, umpteenth-checked my code and it seems okay.
Then I tried even the most basic file opening programs and it still won't open the dang file.
This is merely a practice program. I took it directly from the book. The code compiles successfully but when it runs. Without fail it goes to the Error opening student file
Maybe I need a better understanding of files but my book isn't very helpful. I think it (maybe?) might be a setting in Visual Studio I have to change????Code:#include <stdio.h> int getstu(FILE* spstu, int* stuid, int* exam1, int* exam2, int* final); int writestu(FILE* spgrades, int stuid, int average, char grade); void calcgrade(int exam1, int exam2, int final, int* average, char* grade); int main(void) { FILE* spstu; FILE* spgrades; int stuid; int exam1; int exam2; int final; int average; char grade; printf("Begin student grading\n"); if (!(spstu = fopen ("P07-06.DAT", "r"))) { printf("\aError opening student file\n"); return 100; } if (!(spgrades = fopen ("P07-06Gr.DAT", "w"))) { printf("\aError opening grades file\n"); return 102; } while (getstu(spstu, &stuid, &exam1, &exam2, &final)) { calcgrade(exam1, exam2, final, &average, &grade); writestu(spgrades, stuid, average, grade); } fclose(spstu); fclose(spgrades); printf("End student grading\n"); return 0; } int getstu(FILE* spstu, int* stuid, int* exam1, int* exam2, int* final) { int ioresult; ioresult = fscanf(spstu, "%d%d%d%d", stuid, exam1, exam2, final); if(ioresult == EOF) return 0; else if(ioresult != 4) { printf("\aError reading data\n"); return 0; } else return 1; } void calcgrade(int exam1, int exam2, int final, int *average, char* grade) { *average = (exam1 + exam2 + final) / 3; if (*average >= 90) *grade = 'A'; else if(*average >= 80) *grade = 'B'; else if(*average >= 70) *grade = 'C'; else if(*average >= 60) * grade = 'D'; else *grade = 'F'; return; } int writestu(FILE* spgrades, int stuid, int average, char grade) { fprintf(spgrades, "%04d %d %c\n", stuid, average, grade); return 0; }



LinkBack URL
About LinkBacks



Or wait until a VS user sees that post 
. After all, the Web uses slash, Unix uses slash, MacOS X uses slash (well, that's Unix too), etc.