Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointing dereference inside a struct error

i have a function to create a circular list, i am having issues compiling, not sure if it is syntax, appreciate if someone 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 flags an error in the last line:

"Member reference base type 'struct node*' is not a structure or union"

Any ideas why ? thanks

like image 934
jelipito Avatar asked Jan 15 '23 06:01

jelipito


1 Answers

You probably want

  (*tailRef)->next = *listRef;

as the last assignment.

You cannot write tailRef->next since tailRef is a pointer to a pointer.

I also suggest just coding Push(listRef, "Some string"); instead of your Push(&*listRef, "Some string"); for readability reasons.

like image 62
Basile Starynkevitch Avatar answered Jan 22 '23 15:01

Basile Starynkevitch