I'm trying to print a two-dimensional array through in a loop for
only the array it's returned through a function that I've created. I'm suspecting that the error should be in it but I can not find the error
#include <stdio.h>
#define DIM 2
int *retorna_matriz2D();
int mat2D[DIM][DIM];
int main(){
int x, y;
int *r = retorna_matriz2D(mat2D);
for(x = 0; x < DIM; x++){
for(y = 0; y < DIM; y++){
printf("%d", r[x][y]); // LINHA 13
printf("\n");
}
}
return 0;
}
int *retorna_matriz2D(int mat[][DIM]){
int x, y;
for(x = 0; x < DIM; x++){
for(y = 0; y < DIM; y++){
mat2D[x][y] = 2;
}
}
for(x = 0; x < DIM; x++){
for(y = 0; y < DIM; y++){
printf("%d", mat[x][y]);
printf("\n");
}
}
return *mat;
}
The compiler points out that it has an error on line 13 with the message
subscripted value is neither array nor pointer nor vector
supposedly indicating that the error is in the line of printf()
but I do not see anything wrong, where would be the error of this code? another thing is also that the for
loop within the retorna_matriz2D()
function is executed but that of my main()
function, not indicating that my array was assigned to my *r
pointer.