Can you please point out to me how can I correctly pass a 2d dynamically allocated array into a function? My problem is that I cannot know the size of the two dimensions beforehand, and I always read that the siez of the last dimension must always be passe with the array.
I've managed to get round this by using something like:
This works, but valgrind says that there is an error (which I cannot understand what it's saying on the output). I can verify that this is passed as intended (all values in the 2D array are ok), but I'm sure there's something wrong and that there should be a better way to do this.Code:/* function declaration */ void function(double **array2d, int rows, int cols) /* calling the function from main */ function(array2d, rows, cols)
Can anyone please explain to me a better way to do this? (if how I've done this above is indeed wrong)