如何摆脱不兼容的指针类型警告/错误的初始化?

use*_*891 1 c pointers

我试图在C中编写一个链表程序,但是我继续从不兼容的指针类型警告/错误中获取初始化.我怎么摆脱这个?你能解释一下是什么问题吗?以下是我的程序的简化版本:

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...
}
Run Code Online (Sandbox Code Playgroud)

谢谢

mu *_*ort 5

我想你想struct node *struct Node *struct node:

typedef struct node
{
    int contents;
    struct node *nextNode; /* here */
} Node;
Run Code Online (Sandbox Code Playgroud)

并且不要转换返回值malloc,不需要它.