So say I am reading a 2d array from a textfile, and I don't happen to know what the dimensions will be, thus leading me to using malloc. That being said, here is my failed attempt hopefully you guys can follow through and guide me because I'd LOVE to know how to do this!
void 2dArray(double **arr, int N, int M) {
int i,j;
FILE *fp;
fp = fopen("array.txt", "r");
for(i=0; i < N; i++) {
for(j=0; j < M; j++) {
fscanf(fp, "%lf", &arr[i][j]);
}
}
}
int main() {
int **array;
// How do I initialize this??
// heres my attempt:
array = (double **)malloc(sizeof(double*);
2dArray(array, N, M);
//Where would I get N and M?