i have an assignment, which is required to do a maze game.
but i have a problem with global variable.
the question in brief is that i can print out the char 2d-array if i declare it as a global variable but it is not good to use global variable.
i am new to c++, hope someone can help me, thanks in advance :)
char maze[][1] should be char maze[][7] and you don't pass maze to moveMaze at all. Also, maze[][] is not the right way to pass an array. Plain maze is what you need.
Do you see how you declared your printMaze() function? That number in the square brackets needs to be 7 (the length of the second dimension of your array), not 1.
Also, although some compilers support void main(), your main function should be int main().
Hamsterman already answered your question (I think), but I'll rehash it.
The [][] behind the name of an array are not necessary when you pass it, in fact I think (I've never tried) I think this will result in a syntax error. Remove them and it should work just fine.
sorry i have another question
for this code i am using a 7*7 arrays,
so when i pass the array i would write char maze[][7] (in other function's parameter),
but what if i used 10*10 array, for example, how should code it?
no, that is not what i meant.
u declare an array of any size, then i do not have to change any code in other functions.. something like this
(because later i will have to do a header file and each function as a cpp file)
If you want to be able to pass any array to the function, you'll have to stick to 1d ones. Notice that arr2d[x][y] is the same as arr1d[x+y*width]. Don't forget to pass width and height with the array.