【发布时间】:2017-11-02 18:41:25
【问题描述】:
我在 C 中创建了一个联系人链接列表。它运行良好。但现在我想为指定的联系人(按姓名)编写删除函数,我得到了Error:"dereferencing pointer to incomplete type"。这是我的代码:
struct contact
{
char name[100];
char number[20];
struct contact *next;
};
int deleteByName(struct contact **hptr, char *name)
{
struct student *prev = NULL;
struct student *temp = *hptr;
while (strcmp(temp->name /*The Error is Here*/ , name) != 0 && (temp->next) != NULL)
{
prev = temp;
temp = temp->next;
}
if (strcmp(temp->name, name) == 0)
{
if (prev == NULL)
*hptr = temp->next;
else
prev->next = temp->next;
free(temp);
return 0;
}
printf("\nNAME '%s' WAS NOT FOUND TO BE DELETED.", name);
return -1;
}
我想知道为什么我会收到这个错误(尽管定义了 struct contact.)。谢谢。
【问题讨论】:
-
可能是因为你定义了
struct contact,但是temp被定义为指向struct student的指针。 -
您好,欢迎来到 StackOverflow!遗憾的是,您没有提供足够的代码让我们能够正确地帮助您解决问题。请阅读How to Ask 并使用minimal reproducible example 更新您的问题。
标签: c struct dereference