Request for member 'x' in something not a structure [closed]

1

Hello, how I have reviewed my code but I can not see my error. Could someone enlighten me? The problem arises when trying to access 'end'. By removing these lines and de-commenting the lines that were already there, it works perfectly. I just want to add this pointer to facilitate data insertion

struct lista
{
    int dato;
    struct lista *siguiente; 
    struct lista *fin; //Nuevo apuntador a implementar. 
};

void agregar(struct lista **primero, int r)
{
    struct lista *nvo = (struct lista*)malloc(sizeof(struct lista));

    if(nvo == NULL)
        printf("\nERROR memoria insuficiente...\n");
    else
    {
        nvo->dato = r;
        nvo->siguiente = NULL;

        if(*primero == NULL)
        {
            *primero = nvo;
            *primero->fin = nvo; //Primer intento de acceder a fin
        }
        else
        {
            // Auxiliar para recorrer la lista
            /*
            struct lista *aux1;

            aux1 = *primero;

            while(aux1->siguiente != NULL)
                aux1 = aux1->siguiente;

            aux1->siguiente = nvo;
            */
            *primero->fin->siguiente = nvo; //Segundo intento
            *primero->fin = nvo; //Tercer intento
        }
    }
}

The error shown is the title of the question:

    
asked by Agustin Aguilar 25.04.2017 в 06:01
source

1 answer

1

in this case you must use parentheses:

    if(*primero == NULL)
    {
        *primero = nvo;
        (*primero)->fin = nvo;
    }
    else
    {
        // Auxiliar para recorrer la lista
        /*
        struct lista *aux1;

        aux1 = *primero;

        while(aux1->siguiente != NULL)
            aux1 = aux1->siguiente;

        aux1->siguiente = nvo;
        */

        (*primero)->fin->siguiente = nvo;
        (*primero)->fin = nvo;
    }

This is due to precedence in operations. Greetings.

    
answered by 25.04.2017 / 06:37
source