C: Error allocating memory on ADT 1 class

42 Views Asked by At

i'm having trouble with a ADT 1 class. I'm trying to initializing a vector of pointer to a struct, but something doesn't work

Inside Divisione.h i had:

typedef struct divisione_t *divisione_s;

In Divisione.c we can find:

#define DEP 4

typedef struct{
    int ndip, smin, sott;
}Req;

 typedef struct{
    char *code;
    Req *r;
}divisione_t;

static Req InitReq();

divisione_s *InitDiv(int ndiv){
    divisione_s *div;

    div = (divisione_s *) calloc(ndiv, sizeof(*div));
    if(div == NULL)
        exit(-1);

    for(int i=0; i<ndiv; i++){
        div[i]->r = (Req *) calloc(DEP, sizeof(Req));
        if(div[i]->r == NULL)
            exit(-1);

        for(int j=0; j<DEP; j++)
            div[i]->r[j] = InitReq();
    }

}

static Req InitReq(){
    Req r;
    r.ndip = -1;
    r.smin = -1; 
    r.sott = -1;
    return r;
}

The error is on line: div[i]->r = (Req *) calloc(DEP, sizeof(Req)); and it say "error: dereferencing pointer to incomplete type 'struct divisione_t"

thanks in advance if anything other is needed tell me

0

There are 0 best solutions below