Donc se qui serait mieux serait de faire ceci
void get_info(u_info_t *info, char *tmp);
Cette fonction va remplir le pointeur info.
et dans u_info_t *fill_u_info je met
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 30
|
u_info_t *fill_u_info(int len, char **name, int size)
{
int i;
u_info_t *tab_info = (u_info_t *) calloc(len, sizeof(u_info_t));
u_info_t *info_tmp;
char **tmp = name
if (tab_info != NULL)
{
for (i = 0; i < size; i++)
{
info_tmp = tab_info + i;
get_info(info_tmp, *tmp);
// si get_info foire il met info_tmp a NULL.
if (info_tmp == NULL)
{
// on desalloue tab_info;
// ....
tab_info = NULL;
break;
}
tmp++;
}
}
return tab_info;
} |
Ceci me semble effectivement mieux. Pourquoi allouer de la memoire pour un pointeur alors que l espace est deja alloue dans un tableau.
Cela vous semble aussi meilleur ?
Partager