I am using a book to learn about linked lists. I am going through the exercises and I find this exercise:
Assume the following definitions:
Code:
struct gradeNode {
char lastName[20];
double grade;
struct gradeNode *nextPtr;
};
typedef struct gradeNode GradeNode;
typedef struct GradeNode *GradeNodePtr;
Create a new node of type GradeNode that's pointed to by pointer newPtr of type GradeNodePtr. Assign the string "Jones" to member lastName and the value 91.5 to member grade (use strcpy). Provide any necessary declarations and statements.
The book suggests this as the code to do this:
Code:
GradeNodePtr newPtr;
newPtr = malloc(sizeof(GradeNode));
strcpy(newPtr->lastName, "Jones");
newPtr->grade = 91.5;
newPtr->nextPtr = NULL;
My IDE doesn't like this. It gives the error "pointer to incomplete class type not allowed." My belief is that this means that newPtr might have allocated space for a GradeNode, but it doesn't actually point to a GradeNode. There are no lastName or grade members for it to point to.
My question is then, how do I best preserve the spirit of the question and code it correctly?
*******************
EDIT:
It looks like I made a mistake in the definitions.
Code:
typedef struct GradeNode *GradeNodePtr;
is supposed to be
Code:
typedef GradeNode *GradeNodePtr;
So in typing this post out, I found what the problem was.