Good day!
Our teacher asked us to make a student list using a linked list. His condition is to add new student info into a list in a way that it will be sorted according to the grades of the student in descending order. An error occurs every time i run the program. My code is as follows. Am i on the right path or am i missing something important? What causes the error? Your reply would be highly appreciated. Thank you in advance.
typedef struct student{
char name[11];
unsigned int grade;
struct student* next;
}NODE;
int main (void){
NODE *head, *std;
std = new_student();
}
I think the bug is probably that you don’t initialize
headto NULL inmainbefore passing it toadd_student, but there are some other issues:add_studentalways returns on the first attemptmalloc, but that’s not going to be the problem.<stdlib.h>(for malloc) or<stdio.h>(for printf).