I have this error with lists in c "[Error] request for member 'next' in something not a structure or union"

0

When trying to compile gives me the error

[Error] request for member 'siguiente' in something not a structure or union

and I do not understand why.

This is the code:

typedef struct nodo{

int dato;
struct Nodo *siguiente;

}Nodo;

typedef Nodo *list;
//typedef Nodo *Pnodo;

//Nodo *inicio,*inicio2,*ultimo,*ultimo2;

void agregar_lista1(list *inicio,list *ultimo);
void agregar_lista2(list *inicio2,list *ultimo2);
void mostrar_lista();

int main (){
int op;

list inicio = NULL ,inicio2 = NULL,ultimo = NULL,ultimo2 = NULL;

do{

    printf ("MENU");
    printf ("\nOp1 Ingresar nodo en la lisata 1");
    printf ("\nOp2 Ingresar nodo en la lisata 2");
    printf ("\nOp3 Mostar los datos almacenados en la lista");
    printf ("\nOp4 Mostrar suma de las listas anteriores\n\n");
    scanf ("%d",&op);

    switch(op){

        case 1:
            agregar_lista1(&inicio,&ultimo);
            break;
        case 2:
            agregar_lista1(&inicio2,&ultimo2);
            break;
        case 3:
            mostrar_lista(inicio);
             break; 
        case 4:

        break;          
    }
}while (op!=4);

return 0;
}

void agregar_lista1(list *inicio,list *ultimo){
Nodo *nuevo;

nuevo = malloc(sizeof(Nodo));

if (nuevo==NULL){
    printf ("\nNo se pudo crear el nodo\n");
}

printf ("Ingrese un numero entero positivo: ");
scanf ("%d",&nuevo->dato);

if (inicio == NULL){

    nuevo->siguiente = *inicio;
    *inicio = nuevo;
    *ultimo  = nuevo;
}
else{
    /* en la linea de abajo es donde me da el error */
    *ultimo->siguiente = nuevo;
    *ultimo = nuevo; 
    nuevo->siguiente = NULL;

}
    
asked by Jose Ignacio Gonazález 25.04.2017 в 22:46
source

1 answer

1

You must place parentheses, like this:

(*ultimo)->siguiente = nuevo;

This is due to the precedence of the operators. Greetings.

    
answered by 26.04.2017 / 07:41
source