gpt4 book ai didi

C 错误解引用指向不完整类型链表 dic 的指针

转载 作者:行者123 更新时间:2023-11-30 15:46:09 24 4
gpt4 key购买 nike

大家好,我已经查看了其他具有类似问题的问题,但找不到类似的内容。我在代码的第 69 行收到错误(按照标题),但我不知道如何修复它。我的代码无法编译 atm。该程序旨在接受键值对并形成排序的字典链表。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
int key;
char value[256];
struct node *next;
} node;

void findloc(int key, node*headnode);
void insert(node*newinserte, node*previous, node*after);

int main()
{
makedic();
}

int makedic()
{
int keydata, once;
int compareval = 0;
int i = 0;
char valuedata[256];
node * root, *head, *tmp;
head = NULL;
while (scanf("%d %s", &keydata, &valuedata) != EOF)
{
root = (node*) malloc(sizeof(node));
root->key = keydata;
strcpy(root->value, value data);
root->next = head;
head = root;
if (head != NULL && once == 0)
{
tmp = head;
once++;
}
findloc(root->key, tmp);
}
/*for(; p1->next!=NULL;p1 = p1->next)
{
for (p2 = p1->next;p2!=NULL;p2=p2->next)
{
if(p1->key>p2->key)
{
int temp = p1 ->key;
p1 ->key = p2->key;
p2 ->key =temp;
compareval = compareval +1;
}
}
}*/
//root = root -> next;
while (root)
{
printf("%d %s\n", root->key, root->value);
root = root->next;
}
printf("%d\n", compareval);
}

void findloc(int keysearch, node*headnode)
{
int i;
node*head, *root;
head = headnode;
while (headnode->next != NULL )
{
/*line 69*/ if (keysearch < headnode->next->key) //error is here
{
if (keysearch > headnode->key)
{
//insert(headnode ,headnode->next,headnode->next->next );
}
}
}
}

void insert(node*newinserte, node*previous, node*after)
{
int tmp = after;
previous->next = newinserte;
newinserte->next = tmp;
}

最佳答案

这个

typedef struct
{
int key;
char value[256];
struct node *next;
} node;

应该是这样的:

typedef struct node
{
int key;
char value[256];
struct node * next;
} node;

否则成员struct node * next将指向未知类型,即struct node

<小时/>

注意:虽然前者完全有效,但为了减少可能的混淆,我将按以下方式声明它:

typedef struct node
{
int key;
char value[256];
struct node * next;
} Node;

关于C 错误解引用指向不完整类型链表 dic 的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18545668/

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