Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C、 从另一个文件调用链表函数_C_Linked List - Fatal编程技术网

C、 从另一个文件调用链表函数

C、 从另一个文件调用链表函数,c,linked-list,C,Linked List,我有两个文件,list_funcs.c和list_mgr.c。List_funcs.c具有将节点插入链接列表的功能: #include <stdio.h> #include <string.h> #include <stdlib.h> struct data_node { char name [25]; int data; struct data_node *next; }; struct data_node * insert (struct data_n

我有两个文件,list_funcs.c和list_mgr.c。List_funcs.c具有将节点插入链接列表的功能:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct data_node {
char name [25];
int data;
struct data_node *next;
};

struct data_node * insert (struct data_node **p_first, int elem) {

struct data_node *new_node, *prev, *current;
current=*p_first;
while (current != NULL && elem > current->data) {
   prev=current;
   current=current->next;
} /* end while */
/* current now points to position *before* which we need to insert */
new_node = (struct data_node *) malloc(sizeof(struct data_node));
new_node->data=elem;

new_node->next=current;
if ( current == *p_first ) /* insert before 1st element */
   *p_first=new_node; 
else                       /* now insert before current */
   prev->next=new_node;
/* end if current == *p_first */
return new_node;
};

函数有三个参数,您只传递前两个

struct data_node * insert (struct data_node **, int, char *);
需要将指针传递给
数据\u节点*
,然后是
int
,最后是
char*
类型


令人困惑的是,您对函数的定义也与声明不匹配,定义中省略了最后一个
char*

您对
insert
的定义如下:

struct data_node * insert (struct data_node **p_first, int elem)
struct data_node * insert (struct data_node **, int, char *);
但标题中的声明如下所示:

struct data_node * insert (struct data_node **p_first, int elem)
struct data_node * insert (struct data_node **, int, char *);

注意末尾的
char*
。您可能想删除它以使其匹配。

您在
列表\u func.h
中的函数原型有一个额外的参数:

struct data_node * insert (struct data_node **, int, char *);
/*                one of these doesn't belong:  ^    ^ */

因此,
list\u mgr.c
中的函数定义与
list\u funcs.c
中的调用匹配,
list\u func.h
中的原型不匹配。

嗯,有点像。转发声明与实现不匹配,这才是真正的问题。您需要首先在
main()
中初始化
,但这不是编译问题。在list\u funcs.c文件中插入
inlcude“list\u funcs.h”
,编译器将解释代码的错误。