我是 C 编程新手。出于教育目的,我决定创建一个模块化项目 - 一个线性单链表和一个按键删除元素的函数。问题是我无法在主文件中调用这个函数。请帮忙(ノ_<。)
//list.h
//structure
typedef struct List_Item *List;
struct List_Item
{
int key;
List next;
};
//funstion prototipe
void DeletingByKeyCStyle(List**, int);
//list.c
void DeletingByKeyCStyle(List *p, int x) {
List q;
while (*p != NULL && (*p)->key == x) {
q = *p;
*p = (*p)->next;
free(q);
}
if (*p == NULL) return;
q = *p;
while (q->next != NULL) {
if (q->next->key == x) {
List temp = q->next;
q->next = temp->next;
free(temp);
} else {
q = q->next;
}
}
}
//main.c
DeletingByKeyCStyle(&p, 4); //doesn't work
您是否包含#include“list.h”