问题遇到的现象和发生背景
[Error] ld returned 1 exit status
问题相关代码,请勿粘贴截图
#include<stdio.h>
typedef struct QUOTE
{
char speaker[128];
char content[1024];
struct QUOTE* next;
} quote;
void Quote_add();
void Quote_delete();
void Quote_all_show();
void Quote_modify();
void Speaker_search();
void quit();
void quit(quote* quoteCurrent) //退出
{
quote* quiting;
while (quoteCurrent != NULL)
{
*quiting = *(quoteCurrent->next);
free(quoteCurrent);
quoteCurrent = quiting;
}
}
void Quote_add(quote* quoteCurrent) //添加语录
{
extern numberCommand;
quote* new = (quote *)malloc(sizeof(quote));
if (new == NULL)
{
printf("你他妈中头奖了,内存分配失败了!");
}
printf("请输入语录内容:");
scanf("%s",quoteCurrent->content);
printf("请输入语录来源:");
scanf("%s",quoteCurrent->speaker);
if (quoteCurrent == NULL)
{
quoteCurrent = new;
}
else
{
quoteCurrent->next = new;
quoteCurrent = new;
}
numberCommand = 0;
}
void Quote_all_show(quote* quoteCurrent) //展示所有语录
{
extern numberCommand;
quote* quoteShowing = quoteCurrent;
int numberQuote = 0;
while (quoteShowing != NULL);
{
printf("%d.\n%s\n——%s\n\n",numberQuote++,quoteShowing->content,quoteShowing->speaker);
quoteShowing = quoteShowing->next;
}
numberCommand = 0;
}
void Quote_delete(quote* quoteCurrent) //删除语录
{
extern numberCommand;
Quote_all_show(quoteCurrent);
printf("要删除第几个?");
int numberQuoteTargetDelete = 0;
quote* quoteTargetDelete = quoteCurrent;
scanf("%d",&numberQuoteTargetDelete);
int i = 0;
for(i=0;i<numberQuoteTargetDelete-1;i++);
{
quoteTargetDelete = quoteTargetDelete->next;
}
free(quoteTargetDelete->next);
quoteTargetDelete->next=quoteTargetDelete->next->next;
numberCommand = 0;
}
void Quote_modify(quote* quoteCurrent) //修改语录
{
extern numberCommand;
Quote_all_show(quoteCurrent);
printf("要修改第几个?");
int numberQuoteModify = 0;
scanf("%d",&numberQuoteModify);
int j = 0;
quote* quoteTargetModify = quoteCurrent;
for(j=0;j<numberQuoteModify;j++)
{
quoteTargetModify=quoteTargetModify->next;
}
printf("修改人物【7】还是语句【8】?");
scanf("%d",&numberCommand);
if (numberCommand == 7)
{
printf("请输入人物:");
scanf("%s",quoteTargetModify->speaker);
}
if (numberCommand == 8)
{
printf("请输入语录内容:");
scanf("%s",quoteTargetModify->content);
}
numberCommand = 0;
}
void Speaker_search(quote* quoteCurrent) //展示指定人物的所有语录
{
extern numberCommand;
printf("请输入人物名称:");
char speakerTarget[128];
scanf("%s",&speakerTarget);
quote* quoteShowing = quoteCurrent;
int numberQuote = 0;
while (quoteShowing != NULL);
{
if (quoteShowing->speaker == speakerTarget)
{
printf("%d.\n%s\n\n",numberQuote++,quoteShowing->content);
}
quoteShowing = quoteShowing->next;
}
numberCommand = 0;
}
int main(void)
{
int numberCommand = 0;
quote* quoteCurrent = NULL;
while (numberCommand == 0)
{
printf("你要干嘛?\n【1】添加语录\n【2】删除语录\n【3】查看所有语录\n【4】修改语录\n【5】查找人物\n【6】退出\n");
scanf("%d", &numberCommand);
if (numberCommand == 1)
{
Quote_add(quoteCurrent);
}
if (numberCommand == 2)
{
Quote_delete(quoteCurrent);
}
if (numberCommand == 3)
{
Quote_all_show(quoteCurrent);
}
if (numberCommand == 4)
{
Quote_modify(quoteCurrent);
}
if (numberCommand == 5)
{
Speaker_search(quoteCurrent);
}
if (numberCommand == 6)
{
quit(quoteCurrent);
}
}
return 0;
}
运行结果及报错内容
D:\C\语录本\语录本.c In function 'quit':
23 3 D:\C\语录本\语录本.c [Warning] implicit declaration of function 'free' [-Wimplicit-function-declaration]
23 3 D:\C\语录本\语录本.c [Warning] incompatible implicit declaration of built-in function 'free'
D:\C\语录本\语录本.c In function 'Quote_add':
30 9 D:\C\语录本\语录本.c [Warning] type defaults to 'int' in declaration of 'numberCommand'
31 2 D:\C\语录本\语录本.c [Warning] implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
31 24 D:\C\语录本\语录本.c [Warning] incompatible implicit declaration of built-in function 'malloc'
D:\C\语录本\语录本.c In function 'Quote_all_show':
54 9 D:\C\语录本\语录本.c [Warning] type defaults to 'int' in declaration of 'numberCommand'
D:\C\语录本\语录本.c In function 'Quote_delete':
67 9 D:\C\语录本\语录本.c [Warning] type defaults to 'int' in declaration of 'numberCommand'
78 2 D:\C\语录本\语录本.c [Warning] incompatible implicit declaration of built-in function 'free'
D:\C\语录本\语录本.c In function 'Quote_modify':
85 9 D:\C\语录本\语录本.c [Warning] type defaults to 'int' in declaration of 'numberCommand'
D:\C\语录本\语录本.c In function 'Speaker_search':
113 9 D:\C\语录本\语录本.c [Warning] type defaults to 'int' in declaration of 'numberCommand'
C:\Users\L25773~1\AppData\Local\Temp\ccrx3Hcg.o 语录本.c:(.rdata$.refptr.numberCommand[.refptr.numberCommand]+0x0): undefined reference to `numberCommand'
D:\C\语录本\collect2.exe [Error] ld returned 1 exit status
我的解答思路和尝试过的方法
看了https://blog.csdn.net/e_t_e_r_n_i_t_y/article/details/109982282
我想要达到的结果
编译通过