Probleme Re Allocation dynamique 2D
Bonjour,
J'ai un probleme de reallocation dynamique. Pas grand chose a expliquer, un probleme qui doit souvent sortir je suppose mais je ne vois pas la solution. voici un echantillon de mon programme:
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 41 42 43 44 45 46
| void _tmain(int argc, _TCHAR* argv[])
{
int **TOC_R;
TOC_R = (int **)malloc(100 * sizeof(int *));
for (int i = 0; i < 100; i++)
{ TOC_R[i] = (int *)malloc (20 * sizeof(int));}
int **TOC_C;
TOC_C = (int **)malloc(100 * sizeof(int *));
for (int i = 0; i < 100; i++)
{ TOC_C[i] = (int *)malloc (20 * sizeof(int));}
for (int p=0;p<NbFile+1;NbFile++)
{
for (int q=0;q<NbFile+1;NbFile++)
{
Nb_R=LireFichier(Tab2D, namefile[p]);
TOC_R = (int **) realloc(TOC_R, 20*sizeof(int *));
for (int i = 0; i < Nb_R; i++)
{ TOC_R[i] = (int *) realloc (TOC_R[i],20 *sizeof(int));}
Nb_C=LireFichier(Tab2D, namefile[q]);
TOC_C = (int **) realloc(TOC_C, 20*sizeof(int *));
for (int i = 0; i < Nb_C; i++)
{ TOC_C[i] = (int *) realloc (TOC_C[i],20 *sizeof(int));}
[...] // traitement en lecture sur ces tableaux
for (int f = 0 ; f< Nb_C; f++)
{
free(TOC_C[f]);
TOC_C[f] = NULL ;
}
free(TOC_C);
TOC_C=NULL;
for (int f = 0 ; f< Nb_R; f++)
{
free(TOC_R[f]);
TOC_R[f] = NULL ;
}
free(TOC_R);
TOC_R=NULL;
}
}
} |
Je ne vois pas ce qui ne vas pas. d'un autre coter je ne suis pas sur que le malloc soit bien utiliser.
je suis preneur pour toutes corrections ou autre solutions.
Merci d'avance