This is my first post on cprogramming.com, so I apologize if this is in the wrong section or the answer is easily found elsewhere.
I'm working on a program that will read in student grades from a file and echo them back out to another file with an average semester grade and letter grade.
My problem is that when my code attempts to read in the second student's grades, the program fails for no apparent reason.
here is the code giving me the problem:
My program seems to run through the first for loop once without a problem, but on the second run through, my program fails when it reaches the fscanf function in the second for loop.Code:... int n = 0, i = 0, a = 0, b = 0; fscanf(read, "%d,%d\n", max_numb_students, numb_grades); n = *max_numb_students; i = *numb_grades; *student_list = (struct student*) malloc(n*sizeof(struct student*)); for (n=0;n<*max_numb_students;n++){ student_list[n]->lastname = fget_string(read, 1); printf("%s,", student_list[n]->lastname); student_list[n]->firstname = fget_string(read, 2); printf("%s ", student_list[n]->firstname); fscanf(read, "%d", &b); student_list[n]->id = b; printf("%d ", student_list[n]->id); student_list[n]->grades = (int *) malloc(i*sizeof(int *)); for (a=0;a<i;a++){ fscanf(read, "%d ", &b); student_list[n]->grades[a] = b; printf("%d ", student_list[n]->grades[a]); } ...
I would appreciate ANY help, as I'm a beginner.
Thanks in advance.



LinkBack URL
About LinkBacks


