I've been trying to write this for quite a while, and still have a lot of problems. I know it is still a mess, can't figure out a few computations (real headache), but at the moment the worst problem is that my program does not open a file, or at least it seems to me so...

Can someone take a look at it, and tell me what I did wrong that it doesn't open that file??? And if you have any hints about the computations, I'd be really grateful...

The file contains a formatted input which is sorted alphabetically data about each course. The program is to look for all the courses a student took and compute his/her gpa...

The student.dat file contains this:Code:

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

/* type definitions */

struct StudentData {

int idnum;

char name[15];

char code[5];

int credits;

char grade[1];

int gradenum;

double gradecredit;

};

typedef struct StudentData DATASTU;

int main( void )

{

int TotalSemHrCompl = 0;

int i = 0;

double Sem_gpa = 0.0;

DATASTU students[1000] = {0};

FILE *incoming;

if( (incoming = fopen( "student.dat", "r" )) != NULL )

{

fscanf( incoming, "%d %s %s %d %s\n", &students->idnum,

&students->name, &students->code, &students->credits, &students->grade);

fclose( incoming );

}

else printf("Could not open the file\n");

for(i=0; i<1000; i++)

{

switch(students[i].grade[1])

{

case 'A':

case 'a': students->gradenum = 4; break;

case 'B':

case 'b': students->gradenum = 3; break;

case 'C':

case 'c': students->gradenum = 2; break;

case 'D':

case 'd': students->gradenum = 1;

}

}

for ( i = 0; i < 1000; i++ )

{

students[i].gradecredit = (students[i].grade[1]) * (students[i].credits);

}

for ( i = 0; students[i].idnum != 0; i++ )

{

if ( students[i].idnum != students[++i].idnum )

{

printf( "Student Name: %s\n", students[--i].name);

printf( "Student ID number: %d\n\n", students[++i].idnum);

printf( "Course\t\tCourse\t\tCourse\n");

printf( " Code\t\tCredits\t\tGrade\n");

}

/* trying to write code to print the credits, code and grade for

each course of a student... */

for ( i = 0; students[i].idnum = students[++i].idnum; students[i].idnum != students[++i].idnum, i++)

{

TotalSemHrCompl = students[i].credits + students[++i].credits;

printf( "Total semester Course Credits Completed: %d\n", TotalSemHrCompl );

}

for ( i = 0; students[i].idnum = students[++i].idnum; students[i].idnum != students[++i].idnum, i++)

{

Sem_gpa = (students[i].gradecredit + students[++i].gradecredit) / TotalSemHrCompl;

printf( "Semester Grade Point Average: %.2f\n", Sem_gpa);

}

}

return 0;

}

.Thanks in advance for anything which would helpQuote:

12345678 Bokow, A. NE123 3 A

12345678 Bokow, A. WE234 4 A

12345678 Bokow, A. GH345 2 B

34567890 Sandler, A. WE231 4 B

19876543 Zigow, H. NE876 4 C

19876543 Zigow, H. KJ456 4 A