Übergeben Sie ein mehrdimensionales Array an eine Funktion in C
Ich habe eine Funktion wie diese:
void myfunc(int** arr, int n) {
int i, j;
for(i=0; i<n; ++i) {
for(j=0; j<n; ++j) {
printf("%d,", *(arr + i*n + j) ); // Print numbers with commas
}
printf("\n"); // Just breakline
}
}
In einer anderen Funktion habe ich ein zweidimensionales Array wie dieses:
int main() {
int seqs[8][8] = {
{0, 32, 36, 52, 48, 16, 20, 4},
{0, 16, 20, 52, 48, 32, 36, 4},
{0, 32, 36, 44, 40, 8, 12, 4},
{0, 8, 12, 44, 40, 32, 36, 4},
{0, 32, 36, 38, 34, 2, 6, 4},
{0, 2, 6, 38, 34, 32, 36, 4},
{0, 32, 36, 37, 33, 1, 5, 4},
{0, 1, 5, 37, 33, 32, 36, 4}
};
// Call to myfunc
myfunc(seqs, 8); // This is the idea
}
Aber Compiler werfen mir diesen Fehler:
lab.c: In function 'main':
lab.c:75:5: warning: passing argument 1 of 'myfunc' from incompatible pointer type [enabled by default]
lab.c:4:6: note: expected 'int **' but argument is of type 'int (*)[8]'
Was ist der richtige Weg, um dieses Array zu übergeben (seqs
) Funktionieren (myfunc
)?