I'm wondering is there a way to get the following code to work, or do I have to create a new copy of the function for fixed sizes? If so how can I have a generic function for fixed sizes.
void prettyPrintMatrix_float(float **matrix, int rows, int cols){
int i, j;
for (i = 0; i<rows; i++){
for (j = 0; j<cols; j++){
printf("%10.3f", matrix[i][j]);
}
printf("\n");
}
return;
}
float ppArray[4][10] = {0.0f};
prettyPrintMatrix_float(ppArray, 4, 10);
Gives an error Access violation reading location 0xFFFFF....
float[4][10]doesn't decay tofloat**but(*float)[4]. That is the reason you are getting a violation.float **is notfloat[][]float **would be a pointer to a pointer, which could be an array of arrays. Afloat *could technically point to your matrix, but the issue is that you are now dealing with a decayed pointer; one that does not know how many columns would be in the matrix, so it would not know how to index in two dimension, it would only know how to index in one dimension.