hello, can somebody explain why do I receive this error, when I do:
int boardAux[length][length] = {{0}};
thanks in advance
hello, can somebody explain why do I receive this error, when I do:
int boardAux[length][length] = {{0}};
thanks in advance
You cannot do it. C compiler cannot do such a complex thing on stack.
You have to use heap and dynamic allocation.
What you really need to do:
Use *access(boardAux, x, y, size) = 42 to interact with the matrix.
I am assuming that you are using a C99 compiler (with support for dynamically sized arrays). The problem in your code is that at the time when the compilers sees your variable declaration it cannot know how many elements there are in the array (I am also assuming here, from the compiler error that length
is not a compile time constant).
You must manually initialize that array:
int boardAux[length][length];
memset( boardAux, 0, length*length*sizeof(int) );
You receive this error because in C language you are not allowed to use initializers with variable length arrays. The error message you are getting basically says it all.
6.7.8 Initialization
...
3 The type of the entity to be initialized shall be an array of unknown size or an object type that is not a variable length array type.