invalid application of ‘sizeof’ to incomplete type ‘Student’

Asked by JungleRat

hello :)

i am writing a code for a linked list of students
when i try to ellocate memory for the struct 'student' i get an error

here is the code:

StudentList* insert(StudentList* sl,char* name,int grade,int ID)
{
 Student* toInsert;
 toInsert=Null;

 if (toInsert = (Student*)malloc(sizeof( Student ))==Null ) // the problem is in this line
 {
 printf("not enough memory \n");
 exit(1);
 }
 else

and this is the error i get :
/home/c_ex_1/src/studentlist.c:268: error: invalid application of ‘sizeof’ to incomplete type ‘Student’

please help
thank you

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu kdevelop Edit question
Assignee:
No assignee Edit question
Solved by:
Vincenzo Consales
Solved:
Last query:
Last reply:
Revision history for this message
Best Vincenzo Consales (aquarius987) said :
#1

Hi, maybe you get this error because you are trying to set toInsert to 0 or 1 an the compiler tell you that toInsert isn't a boolean.

The correct statement should be:

if ((toInsert = (Student*)malloc(sizeof( Student )))==Null )

Revision history for this message
JungleRat (yossiturgeman) said :
#2

Thanks Vincenzo Consales, that solved my question.