【发布时间】:2015-06-24 05:25:37
【问题描述】:
嗨,我有以下功能,它给我的错误是
错误:在非结构或联合的情况下请求成员“prev”
void insert(struct node **start){
struct node *temp=*start,*next_node,obj;
int pos=0;
if(temp==NULL)
{
printf("The linked list is empty creating the linked list !!!!!!\n");
next_node=malloc(sizeof(struct node));
if(next_node==NULL)
{
printf("\n Sorry out of Memory !!!!!!! ");
}
else
{
printf("\n Adding the first element in the list !!!!!!");
enterData(&obj);
next_node->data1=obj.data1;
next_node->data2=obj.data2;
next_node->prev=NULL;
next_node->next=NULL;
*start=next_node;
printf("\n The linked list created sucessfully !!!!!!!!! ");
}
}
else{
printf("Enter the position where you want to Enter the element \n");
scanf("%d",&pos);
if(pos==1)
{
printf("\n Adding the element at the begining of the list !!!!! ");
next_node=malloc(sizeof(struct node));
enterData(&obj);
next_node->data1=obj.data1;
next_node->data2=obj.data2;
next_node->prev=NULL;
next_node->next=*start;
*start->prev=next_node; //The error is at this line of code
*start=next_node;
}
}
}
但是如果不是在上面提到的代码行中使用*start 以及注释如果我使用temp 这也是指向结构的指针。然后代码工作正常..?为什么会这样?
【问题讨论】:
-
将
*start更改为(*start)。->可能优先于*。 -
更详细的评论(因为自上一条评论以来已经给出了答案):
start的类型是struct node **。temp的类型是struct node *。因此,您的问题“为什么*start会产生错误而temp不会”是有充分理由的。在这一点上,你甚至不需要知道任何关于操作符优先规则的事情。只需尝试将*start替换为(*start),看看是否能解决问题...