gpt4 book ai didi

c - 错误 : request for member ‘check’ in something not a structure or union

转载 作者:太空宇宙 更新时间:2023-11-03 23:47:02 28 4
gpt4 key购买 nike

我正在尝试在我的代码中实现这个功能

Check QUEUEdelete_check(Q q, int refc){

link *temp;
*temp = q->head;
if(temp->check.refc == refc)
q->head = temp->next;
free(temp);
return temp->check;

while(temp->next != NULL){
if (temp->next->check.refc == refc){
temp->next = temp->next->next;
if(temp->next == NULL)
q->tail = temp;
free(temp->next);
return temp->check;
}
temp = temp->next;
}
printf("Cheque %ld does not exist", refc); }

它给了我这个错误:

Queue.c: In function ‘QUEUEdelete_check’: Queue.c:49:12: error: request for member ‘check’ in something not a structure or union

还有下一个

Queue.c:50:23: error: request for member ‘next’ in something not a structure or union q->head = temp->next; if(temp->check.refc == refc)

我使用的结构是:

typedef struct queue{ link head; link tail;} *Q; 
typedef struct node{Check check ;struct node *next; } *link;
typedef struct Check{long int amount, refe, refb, refc;}Check;

最佳答案

typedef struct node{Check check ;struct node *next; } *link;

因此,link 是指向node 的指针。

link *temp;

temp 是指向link 的指针,或者指向节点的指针。

 if(temp->check.refc == refc)

这也可以写成(*temp).check.refc(*temp) 是指向节点的指针,但您正在使用 . 访问它,这是为结构和 union 保留的。

您需要(*temp)->check.refc 或(最好)重构您的代码以不使用那些讨厌的双指针。

关于c - 错误 : request for member ‘check’ in something not a structure or union,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30197660/

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