【发布时间】:2013-12-10 00:55:45
【问题描述】:
我在初始化数组中结构的(动态)部分时遇到了一些小问题。这就是我到目前为止所拥有的,我正在使用子例程来创建结构
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;
}
这是我的结构:
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;
(对不起语言)
我现在得到的是数组中不是结构的所有内容都很好。但是数组中的所有内容都未声明。
【问题讨论】:
-
标签本身就可以阐明语言。无需在标题中指定它(并浪费空间来命名您的问题:))
-
la_grille是指向t_case_animal的指针数组。您将其分配为t_case_animal的数组