I am trying to write a linked list program in C, however I keep on getting an initalization from incompatible pointer type warning/error. How do I get rid of this? And could you explain what is wrong? What follows is a simplified version of my program:
typedef struct node
{
int contents;
struct Node *nextNode;
} Node;
int main(void)
{
//.......Other code here......
Node *rootNode = (Node *) malloc(sizeof(Node));
rootNode->nextNode = NULL;
//.......Other code here......
addNode(rootNode);
}
addNode(Node *currentNode)
{
//.....Other code here....
Node *nextNode = (currentNode->nextNode); //Error on this line
// ....Other code here...
}
Thanks
I think you want
struct node *notstruct Node *in yourstruct node:And don’t cast the return value from
malloc, it is not needed.