我正在尝试在我的代码中实现这个功能
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/