Allocation de tableau de structure
Bonjour,
J'ai un petit souci de compréhension on dirait bien. Le compilateur braille en me disant :
error: invalid type argument of '->' (have 't_armee')
pour la fonction suivante. Les erreurs provenant des lignes surlignées de la même couleur.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| t_armee *allouerArmee( int *quantite )
{
t_armee *armee = (t_armee*)malloc(2*sizeof(t_armee));
if ( armee != NULL )
{
int i,j;
for ( i=0 ; i<2 ; i++)
{
if ( i==0 )
{
for ( j=0 ; j<quantite[i] ; j++)
{
armee[i]->peloton[j] = (t_peloton*)malloc(sizeof(t_peloton));
}
}
else
{
for ( j=0 ; j<quantite[i] ; j++)
{
armee[i]->peloton[j] = (t_peloton*)malloc(sizeof(t_peloton));
}
}
}
}
else perror("\n allouerArmee : ");
} |
J'aurais aimé aussi pouvoir tester l'allocation de chaque champs. Mais je ne sais pas comment m'y prendre proprement.
Merci d'avance !