I want to have a 3 dimentional matrix of chars as matrix[i][j][k]

i is defined as MAXVAR_A, j and k are not known. There must be problem whit hte free() code because the first time I call the function and allocate memory is ok. But when I call the function for second or third time, i get memory error.

Here is the code:

char **matrix[MAXVAR_A];

makearray(int MAXVAR_J,int MAXVAR_K)

{

int i,j,k;

for (i=0;i<MAXVAR_A;i++)

for (j=0;j<=MAXVAR_J;j++) matrix[i]=new char*;

for (k=0;k<MAXVAR_K;k++)

for (i=0;i<MAXVAR_A;i++)

for (j=0;j<=MAXVAR_J;j++) matrix[i][j]=new char;

.......

code that is working using matrix array

.......

//free matrix

for (i=0;i<MAXVAR_A;i++)

for (j=0;j<=MAXVAR_J;j++) free(matrix[i][j]);

for (x=0;x<=MAXVAR_J;x++)

free(matrix[x]);

}

IMO the problem is you mix up C and C++ allocation/release functions.

Instead of 'free(...)' you have to use 'delete [] ...'

Hope that helps,

ZOPPO