C Error: Dereferencing pointer to incomplete type

2

Good, I am stuck with the error of the matter. I'm trying a simple code, but I do not realize where the error is.

The Error is in the printf

struct nodoLinea {
    char Caracter;
    struct nodoLinea *Siguiente;
};

typedef struct nodoLinea NodoLinea;
typedef NodoLinea *ptrNodoLinea;


struct nodoColumna {
    struct ptrNodoLinea *Linea;
    struct nodoColuma *ptrSig;
};

typedef struct nodoColumna NodoColumna;
typedef NodoColumna *ptrNodoColumna;

int main ()
{
    ptrNodoLinea ptrL = NULL;
    ptrNodoColumna ptrC = NULL;

    ptrC = malloc(sizeof(struct nodoColumna)); /* crea un nodo */
    ptrL = malloc(sizeof(struct nodoLinea)); /* crea un nodo */

    ptrL->Caracter = 'A';
    ptrL->Siguiente = NULL;

    ptrC->Linea = ptrL;
    ptrC->ptrSig =NULL;

    printf("%c",ptrC->Linea->Caracter);


    return 0;
}
    
asked by Alkuy 07.11.2016 в 19:35
source

1 answer

4

The problem is that you are using typedef to hide the structure and the pointer (some people see it as a bad practice, although others do not).

You made the following definitions:

typedef struct nodoLinea NodoLinea;
typedef NodoLinea *ptrNodoLinea;

so that (ptrNodeLinea) = (struct nodeLine *).

Then you try to define the following structure

struct nodoColumna {
    struct ptrNodoLinea *Linea;
    struct nodoColuma *ptrSig;
};

but what is struct ptrNodoLinea *? if you expand (so to speak) the typedef would be something like that

struct struct nodoLinea **Linea

which does not make sense (struct struct is an invalid construction), then the solution is to remove the struct as the asterisk in the line variable, so it would be left.

struct nodoColumna {
    ptrNodoLinea Linea;
    struct nodoColuma *ptrSig;
};

I hope this solves your problem.

    
answered by 07.11.2016 / 19:59
source