I want to move the array in another function (type void), to change the value of the array, but every times i have got an error under gcc
I have those following rules:
- in this exercise it's forbidden to use global variable,
- We want to move the array by reference and not use pointers:
.
#include <stdio.h>
typedef enum {F=0,T=1} Mat;
//==========================//
void unknown(Mat b[][][]){
b[0][0][0]=7;
printf("%d\n",b[0][0][0]);
}
//=========================//
int main(void){
Mat b[2][2][2];
b[0][0][0]=1;
printf("%d\n",b[0][0][0]); //before the unknown
uknown(b);
printf("%d\n",b[0][0][0]); //after unknown
return 0;
}
I have the following error:
test.c:7:18: error: array type has incomplete element type ‘Mat[] {aka enum []}’ void unknown(Mat b[][][]){ ^ test.c: In function ‘main’: test.c:21:9: error: type of formal parameter 1 is incomplete unknown(b); ^
The question is : I need to change the value of the array, not in main, but in the function void unknown, and check in the main (after having change in void unknown values of array Mat b) if this array change this value by reference, what's wrong ? and what do I need to change inside the code ?
(my gcc version: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609)
Mat b[][2][2].b[2][2][2]andb[8]are interchangeable here, and arrays decay into pointers when you pass them to functions, soMat b[8];andvoid unknown(Mat *b)might make your code easier to readb[2][2][2]andb[8]can be equivalent. The first takes three subscripts to find the underlying value; the second only requires one subscript. At the very least, you've grotesquely over-simplified what you're trying to say. At worst, you're flat out wrong.