C 尝试将结构指针作为节点发送到函数

C 尝试将结构指针作为节点发送到函数,c,pointers,struct,C,Pointers,Struct,我在解析函数list\u 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

我在解析函数list\u 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);

}
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;
}

对。我猜编译器正在寻找数据类型列表,当您在
struct post*
中传递时。什么是
列表
。?你在哪里定义过它


此外,头文件中定义的函数的数据类型与实际函数定义不匹配。

由于您没有在任何地方定义LIST,您只需将LIST.h中函数的声明更改为以下内容:

void  list_append   (struct node* n, int item);
void list_append(LIST n, int item)
您正在实现一个链表,因此“列表”实际上只是指向第一个节点的指针

否则,您可以在标题中包含以下内容:

typedef struct node * LIST;
并将函数声明(在.c文件中)更改为以下内容:

void  list_append   (struct node* n, int item);
void list_append(LIST n, int item)

赞成。。。不,我没有在任何地方定义
列表
,只是在头文件中。查找“typedef xxxx LIST”或“define LIST xxxx并发布它,这样我们就可以看到该类型被定义为什么。我也没有看到任何定义的结构节点。标题中的列表是什么意思?这是在LIST.h
typedef结构节点*列表中
是否在list.c中包含list.h?我现在更改了它,list.h已经
typedef结构节点*list,并且list.c具有
无效列表\u追加(列表n,int项)
。我仍然会犯同样的错误。