Originally Posted by
Salem
Prune away unused stuff
Sorry forgot that one line, it was part of a debug attempt.
Originally Posted by
Salem
> arr = (student *) malloc((sizeof(student) * numRecords) + (numRecords * NUMCOURSES * sizeof(course)));
Also, what are you trying to achieve with this?
Without a lot of extra effort, the number of courses is fixed, and all you have is the number of students.
I realize that in the code I posted I had changed the struct declaration of student to incorporate an array of courses of fixed size. That was part of the same debug effort from before. The correct structure is
Code:
typedef struct studentRecord {
char firstName[20];
char lastName[20];
int ID;
course courseInfo[];
} student;
which is what is throwing me for a loop
Originally Posted by
Salem
This does NOT update your local pointer variable with what you malloc'ed in the function.
You need to do something like
studentArray = getStudentArray();
Where your function looks something like this
Code:
student *getStudentArray ( void ) {
student * arr;
// some stuff
arr = malloc ( numRecords * sizeof *arr );
// some more stuff
return arr;
}
That's kind of what I figured. But the problem I ran into was how do I allocate space inside the getStudentArray() for the courseInfo array in the current element of the student array?
Thanks for your help. I will implement your suggestions.