> void main
main returns int
> char user_choice;
> while (user_choice!='z')
This variable is uninitialised at the point you first use it.
> university univ;
This isn't initialised either.
Which is very important when you get to make_file(), since you do
- dereference an uninitialised pointer
- try and realloc an uninitialised pointer
> if (un->ptr==NULL) un->ptr=(student*)realloc(un->ptr,(count+1)*sizeof(student));
The test serves no purpose, since at best it only extends the array once.
In main(), you need this to start off with a NULL pointer
university univ = { 0 };
And this function needs to be something like
int make_file(FILE *in,university *un) {
char buff[BUFSIZ];
int count=0;
while ( fgets( buff, sizeof buff, in ) != NULL ) {
student s;
if ( sscanf( buff, "%s %ld %f %ld",
s.name, &s.id, &s.avg, &s.hw_submit ) == 4 ) {
/* success decode, extend array and copy the info */
void *temp = realloc( un->ptr, (count+1)*sizeof(student) );
if ( temp != NULL ) {
un->ptr = temp; /* update array */
un->ptr[count] = s; /* copy data */
count++; /* one more stored */
} else {
/* no more room, return with what we have */
return count;
}
} else {
/* that line didn't make sense, report it */
fprintf( stderr, "Bad line %s", buff );
}
}
return count;
}