Pregunta

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

¿Fue útil?

Solución

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.

Otros consejos

I think you need to do it as below

(*tailRef)->next = *listRef;

i.e get the struct node * pointed to by tailref, dereference with -> to get the struct node * that is next and then set it to the element pointed to by listRef

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top