我有两个文件, 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;
};
现在我试图像这样从 list_mgr.c 调用这个函数,但是得到错误“函数'insert'的参数太少”:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "list_funcs.h"
int main (void) {
struct data_node *first, *new_node, *ptr;
printf("Insert first node into list\n");
first=ptr=insert(&first, 5);
strcpy(ptr->name,"Alexander");
return 0;
}
为什么我会收到“参数太少”错误,我该如何正确调用它?
头文件 list_func.h 包含:
#define STRINGMAX 25
struct data_node {
char name [STRINGMAX];
int data;
struct data_node *next;
};
struct data_node * insert (struct data_node **, int, char *);