gpt4 book ai didi

c - 多个函数的 undefined reference 错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:26:27 24 4
gpt4 key购买 nike

在运行此 c 程序以实现链表操作时,我遇到了几个函数的 undefined reference 错误,例如对 create_list 的 undefined reference 、对显示的 undefined reference 等。我也在该站点上阅读了有关此错误的信息,但我没有得到这些错误的确切含义。我不知道这个错误,所以请帮助我理解这些错误。

#include < stdio.h >
#include < stdlib.h >
struct node {
int info;
struct node * link;
};
struct node * create_list(struct node * start);
void display(struct node * start);
void count(struct node * start);
void search(struct node * start, int data);
struct node * addatbeg(struct node * start, int data);
struct node * addatend(struct node * start, int data);
struct node * addafter(struct node * start, int data, int item);
struct node * addbefore(struct node * start, int data, int item);
struct node * addatpos(struct node * start, int data, int pos);
struct node * del(struct node * start, int data);
struct node * reverse(struct node * start);
main() {
struct node * start = NULL;
int choice, data, item, pos;
while (1) {
printf("1.Create list\n");
printf("2.Display\n");
printf("3.Count\n");
printf("4.Search\n");
printf("5.Add to empty list/Add at beginning\n");
printf("6.Add at end\n");
printf("7.Ad after node\n");
printf("8.Add before node\n");
printf("9.Add at position\n");
printf("10.Delete\n");
printf("11.Reverse\n");
printf("12.quit\n");
printf("Enter your choice:\n");
scanf("%d", & choice);
switch (choice) {
case 1:
start = create_list(start);
break;
case 2:
display(start);
break;
case 3:
count(start);
break;
case 4:
printf("Enter the elements to be searched:");
scanf("%d", & data);
search(start, data);
break;
case 5:
printf("Enter the element to be inserted");
scanf("%d", & data);
start = addatbeg(start, data);
break;
case 6:
printf("Enter the element to be inserted: ");
scanf("%d", & data);
start = addatend(start, data);
break;
case 7:
printf("Enter thee element to be inserted");
scanf("%d", & data);
printf("Enter the element after which to insert");
scanf("%d", & item);
start = addafter(start, data, item);
break;
case 8:
printf("Enter the element to be inserted: ");
scanf("%d", & data);
printf("Enter the element before which to insert");
scanf("%d", & pos);
start = addbefore(start, data, item);
break;
case 9:
printf("Enter the element to be inserted");
scanf("%d", & data);
printf("Enter the position at which to insert");
scanf("%d", & data);
break;
case 10:
printf("Enter the elements to be deleted");
scanf("%d", & data);
start = del(start, data);
break;
case 11:
start = reverse(start);
break;
case 12:
exit(1);
default:
printf("Wrong choice\n");
}
}
}

最佳答案

您的程序已经声明了函数,但还没有定义它们。您所做的只是告诉它如何调用 create_list,而不是告诉它应该如何实现该功能。

这个文件是否有另一个文件?很有可能,这些函数是在另一个文件中定义的,您需要告诉编译器使用该文件的编译输出来定义这些函数。

关于c - 多个函数的 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50380021/

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