Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C中指向结构的指针_C_Pointers_Struct - Fatal编程技术网

C中指向结构的指针

C中指向结构的指针,c,pointers,struct,C,Pointers,Struct,我正在使用指针和结构在C中实现堆栈。Push和Stack函数工作良好(它们都在内存中创建新元素)。无论如何,pop函数不起作用,我不知道为什么,下面是该函数的代码: int pop(element **lastStackEl) { int poppedValue = *lastStackEl->value; element *temp = *lastStackEl->prev; free(*lastStackEl); *lastStackEl=temp; retu

我正在使用指针和结构在C中实现堆栈。Push和Stack函数工作良好(它们都在内存中创建新元素)。无论如何,pop函数不起作用,我不知道为什么,下面是该函数的代码:

int pop(element **lastStackEl)
{
  int poppedValue = *lastStackEl->value;
  element *temp = *lastStackEl->prev;
  free(*lastStackEl);
  *lastStackEl=temp;
  return poppedValue;
}
error: request for member 'value' in something not a structure or union
int poppedValue = *lastStackEl->value;
这是我的结构:

typedef struct Element {
  int value;
  struct Element *prev;
} element;
编译器在pop函数的第一行和第二行中给出错误:

int pop(element **lastStackEl)
{
  int poppedValue = *lastStackEl->value;
  element *temp = *lastStackEl->prev;
  free(*lastStackEl);
  *lastStackEl=temp;
  return poppedValue;
}
error: request for member 'value' in something not a structure or union
int poppedValue = *lastStackEl->value;
根据,间接(取消引用)运算符(
*
)晚于成员访问运算符(
->
)。因此,如果没有显式括号,您的语句的行为就像

int poppedValue = *(lastStackEl->value);
int poppedValue = (*lastStackEl)->value;
现在,
lastStackEl
是指向
元素的指针
它不能用作成员访问操作符的LHS。这就是错误消息的全部内容

您需要先解除限制
lastStackEl
(以获取
元素*
类型),然后可以使用
->
访问成员
。你应该写