Specifying dereferencing inside a structure error

I have a function to create a circular list, I am having compilation problems, not sure if this is the syntax, please appreciate if anyone can help.

    void CreateCircularList(struct node** listRef, struct node** tailRef)

    {    
    Push(&*listRef, "String 1");
    *tailRef=*listRef;
    Push(&*listRef, "String 2");
    Push(&*listRef, "String 3");
    Push(&*listRef, "String 4");

    *(tailRef->next)=*listRef;

    } 

      

the compiler puts the error on the last line:

"The type of the underlying base element 'struct node *' is not a structure or a union"

Any ideas why? thank

+3


source to share


2 answers


You probably want

  (*tailRef)->next = *listRef;

      

as the last destination.



You cannot write tailRef->next

as it tailRef

is a pointer to a pointer.

I also suggest just coding Push(listRef, "Some string");

instead of yours Push(&*listRef, "Some string");

for readability.

+6


source


I think you need to do it like below

(*tailRef)->next = *listRef;

      



ie get struct node *

pointed to tailref

, dereference with ->

to get struct node *

that is next

and then set to the element pointed tolistRef

+2


source







All Articles