C (not ++) a struct of struct array in struct dynamic initialization troubles malloc

Viewed 131

I have a small trouble initializing (dynamic) parts of my structures that are in an array. This is what i have so far I am using a sub-routine to create the struct

t_grille_animaux creer_grille(int dim_ligne, int dim_col) 
{
    t_grille_animaux grille;

    grille.la_grille = (t_case_animal **) malloc(sizeof(t_case_animal)*dim_ligne*dim_col);

    grille.dim_colonne = dim_col;

    grille.dim_ligne = dim_ligne;

    grille.nb_predateurs = NULL;

    grille.nb_proies = NULL;

    return grille;

}

This is my structure:

typedef struct
{
    t_case_animal ** la_grille; //2D array
    int dim_ligne;
    int dim_colonne;
    int nb_proies;
    int nb_predateurs;
} t_grille_animaux;

typedef struct
{
    t_contenu etat;
    t_animal animal;
} t_case_animal;

typedef enum {VIDE, PROIE, PREDATEUR} t_contenu;

typedef struct
{ 
    int age;           
    int jrs_gestation; 
    int energie;      
    int disponible;    
} t_animal;

(Sorry for the language)

What I get right now is that everything that isn't the struct in the array is fine. But everything in the array is undeclared.

3 Answers
Related