我在解析参数到函数list_append()时遇到问题。混淆我的主要问题是指针结构里面的结构里面的指针...试图将结构指针作为节点发送到函数
该函数是否要求数据类型为“LIST”,并向它传递一个指针?
当我尝试编译此我得到以下错误:
请解释一下像我5.
错误
In file included from main.c:3:0:
list.h:9:7: note: expected 'LIST' but argument is of type 'struct post *'
void list_append (LIST l, int item);
^
list.h
void list_append (LIST l, int item);
的main.c
#include <stdio.h>
#include "list.h"
int main() {
static struct post {
char* str;
struct post* next;
int item;
} head = { 0, NULL };
struct post *p = &head;
struct post post;
list_append(p, post.item);
}
list.c
void list_append(struct node* n, int item)
{
/* Create new node */
struct node* new_node = (struct node*) malloc (sizeof (struct node));
new_node->item = item;
/* Find last link */
while (n->next) {
n = n->next;
}
/* Joint the new node */
new_node->next = NULL;
n->next = new_node;
}
是的...不,我没有在任何地方定义'LIST',只在头文件中。 – user3241763
沿着“typedef xxxx LIST;”寻找一些东西或者可能是#define LIST xxxx并发布它,以便我们可以看到该类型已被定义为。 – Jmc
另外我没有看到任何定义的结构节点。标题中的LIST是什么意思? – pvkc