For my program I need to pass a 2D array of pointers to a function in a separate file. I\'ve written a similarly-syntaxed file below:
#include
#
As has been mentioned, to pass a 2d array to a function, you need to have every dimension but the first declared. However, you can also just pass the pointer, as follows. Note that you should always (unless the array dimension is completely fixed and the function that operates on the array only operates within the array's dimension) pass the length of each array, too.
void setFirst(card_t ***cards, size_t n, size_t m) {
if (n > 0 && m > 0) {
cards[0][0]->state = 1;
}
}
Because referencing an array via code[0][0]
is the same as *(*(code+0)+0*m)
, you can pass two pointers instead of array dimensions.