Hi, all. I've tried and tried to get my head around this, and feel I am almost there, but I'm getting so confused with how many '*' I need! I have a function that takes as input the string of a directory containing a data file, an int and pointers to two uninitialized 2D arrays. The function reads the data file and then allocates memory and fills the arrays accordingly.
This code is probably quite wrong, but the idea is:
char DirWork, buff;
f_ReadData(DirWork, dimension1, &Array1, &Array2);
sprintf(buff,"%lf",Array1); // Causes segmentation fault
void f_ReadData(char *DirWork, int dimension1, double ***Array1ptr, int ***Array2ptr)
int ct, ct2;
double **Array1 = *Array1ptr;
int **Array2 = *Array2ptr;
char FullDirArray1, FullDirArray2;
FILE *d_Array1, *d_Array2;
Array1 = dmatrix(0,dimension1-1,0,3); // allocates memory to Array1 (dimension1 x 3) elements, using nrutil
Array2 = imatrix(0,dimension1-1,0,3); // allocates memory to Array2 (dimension1 x 3) elements, using nrutil
for(ct=0; ct<dimension1; ct++)
for(ct2=0; ct2<3; ct2++)
fscanf(d_Array1, "%lf", &Array1[ct][ct2];
fscanf(d_Array2, "%d", &Array2[ct][ct2];
Array1ptr = &Array1;
Array2ptr = &Array2;
I've missed out error handling here, but I do have some of that in place... not that it's helping. I'm getting a segmentation fault when I try to access the arrays from the main function.
If anyone could help, I'd really appreciate it... I'm seeing *stars! Thank you!