I have a segmentation fault and would like to know where is my mistake.
Let me explain.
In my main, I declare a 3D array: int*** Matricegroupegeneralisant
Then this main uses a function recuperationinfoFich(&matricegroupegeneralisant);
This function is declared as : recuperationinfoFich(int* * * * matricegroupegeneralisant)
This function recuperationinfoFich uses another function recuperationmatricegroupesgeneralisants(matricegroupegeneralisantA[Ni]);
This function is declared as recuperationmatricegroupesgeneralisants( int*** matricegroupegeneralisant)
My code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void allocationdynamiquetableautroisdimdentier(int**** Matrice,int nbniveau, int nbligne, int nbcolonne)
{
int i,j;
*Matrice=(int***) malloc (sizeof(int**)*nbniveau);
for (i=0; i<nbniveau; i++)
{
(*(Matrice))[i]=(int**) malloc (sizeof(int*)*nbligne); // allocation dynamique de la matrice Matrice
for (j=0; j<nbligne; j++)
{
((*(Matrice))[i])[j]=(int*) malloc (sizeof(int)*nbcolonne);
}
}
}
void recuperationmatricegroupesgeneralisants(int*** matricegroupegeneralisantA)
{
(*matricegroupegeneralisantA)[0][1]=1;
}
void recuperationinfoFich(int**** matricegroupegeneralisantA)
{
allocationdynamiquetableautroisdimdentier(matricegroupegeneralisantA,3, 3, 7);
recuperationmatricegroupesgeneralisants(matricegroupegeneralisantA[1]);
}
void main(int args, char **argv)
{
int*** matricegroupegeneralisantA;
recuperationinfoFich(&matricegroupegeneralisantA);
}
With Gdb :
(gdb) r
Starting program: /home/larimsna1/Desktop/a.out
Breakpoint 1, 0x000000000040061a in main ()
(gdb) n
Single stepping until exit from function main,
which has no line number information.
Program received signal SIGSEGV, Segmentation fault.
0x00000000004005c8 in recuperationmatricegroupesgeneralisants ()
(gdb)
recuperationinfoFichandallocationdynamiquetableautroisdimdentierproperly, you do not callrecuperationmatricegroupesgeneralisantsproperly. Or using the passed argument properly inrecuperationmatricegroupesgeneralisants.gdbis going to be much much more helpful if you compile with the flag-ggdb(assuming you're usinggcc).