edit: solution is to declare mainMap as int **mainMap;
then when calling track_heatmap pass &mainMap
finally, inside track_heatmap do *map = rowArray;
Thanks to everyone who helped as well as an alum from my school who reached out
track.c: contains
void track_heatmap(const track *trk, double cell_width, double cell_height,
int ***map, int *rows, int *cols)
The parameter map: I.e. you pass in a pointer and that pointer recieves the data. So to set this up, inside of track_heatmap I've got this code, which simply creates a map (malloc'd 2D array of ints) and then specifies that the 'map' argument points to to said array.
(code inside of track_heatmap function):
if( (nRows >= 0) && (nColumns >= 0) )
{
// Create the 2D Array:
int **rowArray = malloc(sizeof(int*) * nRows);
for(int i=0; i<nRows; i++)
{
rowArray[i] = malloc(sizeof(int) * nColumns);
}
// Step through & initialize every int value in the 2D Array:
for(int i=0; i<nRows; i++)
{
for(int j=0; j<nColumns; j++)
{
rowArray[i][j] = 0;
// int curCell = rowArray[i][j];
}
}
map = &rowArray;
Now in my main function, in a file called Heatmap.c, I actually use this. Heatmap.c
int ***mainMap = malloc(sizeof(int**));
track_heatmap(mainTrack, argWidth, argHeight, mainMap, mainRows, mainCols);
From what I understand, since we passed mainMap as the 'map' argument and track_heatmap assigns &RowArray to be 'map', then mainMap should now POINT to that same 2D array. However, when trying to access *mainMap[0][0] I get the following error:
==30007== Invalid read of size 8
==30007== at 0x4014C4: main (Heatmap.c:120)
==30007== Address 0x0 is not stack'd, malloc'd or (recently) free'd
It's as if mainMap has not been changed by track_heatmap. What should I do?