gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 19:47:35 28 4
gpt4 key购买 nike

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

ma​​in.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,当您传入 struct post * 时。 LIST 到底是什么?你在任何地方定义过它吗?

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

关于c - 尝试将结构指针作为节点发送到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21389365/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com