Access to structure data [closed]

1

The program would have to work with lists in C. It has to be able to read integers that the user enters and make operations with these numbers, such as insert elements in front, show an element and also the possibility of deleting an element entered. But pull the following errors in design time

#ifndef _Lista
#define _Lista

typedef struct
{
    int info, sig;
} nodoL;

typedef nodoL* lista;

void insFront(lista *L, int n);
int mostrar(lista L);
void borrar(lista *L, int n);
#endif

File myLista.c

#include <stdio.h>
#include <stdlib.h>
#include "myLista.h"

void insFront (lista *L, int n){
    lista aux = malloc(sizeof(nodoL));
    aux -> info = n;
    aux -> sig = L; 
    L=aux;
    printf("Se agrego el %d a la lista\n",n);
}

int mostrar(lista L){
    int i=0;
    if (L!=NULL){
        i=1;
        printf(" |%d|->",L->info);
        mostrar(L->sig); //<-warning: passing argument 1 of 'mostrar' makes pointer from integer without a cast [enabled by default]|
    }
    return i;
    }

void borrar(lista *L, int n){
    lista aux = *L; 
    *L = *L -> sig; //<-error: request for member 'sig' in something not a structure or union
    free (aux);   
}

Shoot the following errors:

  

warning: passing argument 1 of 'show' makes pointer from integer without a cast [enabled by default] |

     

error: request for member 'sig' in something not to structure or union |

How can you solve those errors?

    
asked by Alejandro Caro 11.09.2017 в 23:35
source

1 answer

2

The errors are clear as the water, maybe you are not familiar to them because they are in English, let me translate them:

  

alarm: passing argument 1 of 'show' creates a pointer from an integer without a conversion [activated by default]

Why is this happening? The function mostrar has the following signature:

int mostrar(lista L);

The first parameter is of type lista which is an alias of a pointer to nodoL :

typedef nodoL* lista;

Which means that the signature of mostrar would be:

int mostrar(nodoL* L);

The call you are making and causing the error is as follows:

mostrar(L->sig);

The data sig has an integer type ( int ):

typedef struct
{
    int info, sig;
           // ^^^ <----- sig es entero
} nodoL;

So in the call mostrar(L->sig) you're passing an integer ( int ) to a function that expects a pointer to nodoL ( nodoL* ) and this causes the alarm.

  

error: member's request 'sig' in something that is not a structure or union

Member sig of nodoL is n type of whole data ( int ):

typedef struct
{
    int info, sig;
           // ^^^ <----- sig es entero
} nodoL;

But you're treating it like a pointer:

//   v <----- Puntero
*L = *L -> sig
//         ^^^ <----- Entero

Surely you wanted sig to be a pointer to nodoL :

typedef struct nodo
{
    int info;
    struct nodo *sig;
} nodoL;

Do not make an alias of nodo called lista , the nodes are not lists.

    
answered by 12.09.2017 в 09:34