Bonjour à tous,

J'ai un petit soucis avec un tableau. J'ai réussi à allouer la mémoire (ouf) mais je pense que mon code est foireux (... en effet, j'ai une erreur de segmentation) lors de la réalloaction:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
 
int main()
{
 
  int i,j=0;
  char ***tableau=NULL;
  int nombre_de_ligne = 4;
  int tableau_nombre_de_colonne[4]={4, 2, 3, 5};
  //allocation
  tableau =  malloc(nombre_de_ligne * sizeof tableau);
 
	for(i=0; i < nombre_de_ligne; i++)
  {
		tableau[i]= malloc(tableau_nombre_de_colonne[i]*sizeof tableau[i]);
    for(j=0; j<tableau_nombre_de_colonne[i];j++)
    {
		  tableau[i][j] = malloc(65 * sizeof *tableau[i][j]);  
    }  
  }
  //reallocation
  nombre_de_ligne = 6;
  int nouveau_tableau_nombre_de_colonne[6]={1,4, 7, 3, 2,9};
 
  tableau =  realloc(tableau,nombre_de_ligne * sizeof tableau);
  for(i =0; i < nombre_de_ligne; i++)
  {
 
    tableau[i]= realloc(tableau[i],tableau_nombre_de_colonne[i]*sizeof tableau[i]);
 
    for(j=0; j<nouveau_tableau_nombre_de_colonne[i];j++)
    {
      tableau[i][j] = realloc(tableau[i][j],65 * sizeof *tableau[i][j]);  
    }
 
  }
 
}
Merci de votre aide