tableau dynamique de type void *
Bonjour a tous j'ai un projet a rendre bientot et je voudrai savoir se que vous pensez de mon code et des amelioration que je peux y apporter.
je doit creer un emsemble de fonction afin de gerer un tableau dynamiquement.
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 30 31 32 33 34 35 36 37 38 39 40
| //14/11/2006
//tadDynamique.c
#include <stdlib.h>
//creation dans tableau
int creerTab(int taille, void *** tab)
{
*tab=(void**)malloc(taille*sizeof(void *));
if (*tab == NULL)
{
// Gestion du cas où on n'a pas pu allouer
return 0;
}
return 1;
}
//augmentaion de la taille du tableau
int augmenterTailleTAb(int taille, void *** tab)
{
void ** tmp;
// Réallocation
tmp=(void**)realloc(*tab, taille*sizeof(void *));
if (tmp == NULL)
{
return 0;
}
else
{
*tab=tmp;
return 1;
}
}
//Liberation de la memoire occupee
detruireTab(void *** tab)
{
free(*tab);
tab=NULL;
} |