我这里有两个结构。主链表是单词。单词列表的每个节点都有意义
typedef struct node{
char word[20];
struct node2 *meaning;
struct node *next;
}word;
typedef struct node2{
char meaning[100];
struct node2 *next;
}means;
我现在的问题是我不能添加多个含义。我可以只添加 1 个含义,每当我尝试添加时,它会覆盖以前的含义。我该怎么做?这就是我添加意义的方式
word *tmp2=(*head);
means *tmp3;
tmp3=(means *)malloc(sizeof(means));
if(tmp2==NULL){
printf("\n**List still empty, add a word**\n");
return;
}
do{
if(strcmp(tmp2->word,ins)==0){
tmp2->meaning=tmp3;
strcpy(tmp3->meaning,mea);
tmp3->next=NULL;
printf("\n**You have successfully added a meaning**\n");
return;
}
tmp2=tmp2->next;
}while(tmp2!=NULL);
printf("\n**Word is not on the list, cannot add meaning**\n");
return;