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

标签 c

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

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/

相关文章:

c - 在 C 中将不同的线程汇总在一起?

c++ - SSL_CTX_load_verify_locations 和可信证书

c - 如何从文件中读取一个数组,对其进行排序,并将其打印到另一个文件中?

c - 尝试将加密或解密的文件输出到文本文件中

c - 使用 fgets 读取输入(进入无限循环)

c - 使用 FTD2XX C++ 的 QtCreator undefined reference

c++ - 链接 : fatal error LNK1181: cannot open input file 'libclamav.lib'

c - 如何使用结构从文本文件中读取并将其加载到内存中?

c - 将 char 转换为整数并返回值的函数 [C]

c - 如何找到文件中值的最小值/最大值