我试图在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)
谢谢
我想你想struct node *不struct Node *你struct node:
typedef struct node
{
int contents;
struct node *nextNode; /* here */
} Node;
Run Code Online (Sandbox Code Playgroud)
并且不要转换返回值malloc,不需要它.
| 归档时间: |
|
| 查看次数: |
2507 次 |
| 最近记录: |