I've following simple code #include using namespace std; typedef enum {wood , stone} material;
typedef struct{
int x,y;
bool isWall;
material type;
}field;
#define n 16
#define m 12
int x=5;
int y=5;
void display( field **playground ){
for (int j = 0; j < m; j++)
{
for (int i = 0; i < n; i++)
{
if (playground[i][j].isWall )
{
cout << "*";
}
else
if (x == i && y == j){
cout << "O";
}
else {
cout << " ";
}
}
cout << endl;
}
}
int main(){
field playground[n][m];
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
playground[i][j].x=i;
playground[i][j].y=j;
playground[i][j].isWall=(i==0||i==(n-1)||(j==0&&i!=3) ||j==(m-1));
if (playground[i][j].isWall && !(i==3 && j==0))
playground [i][j].type=stone;
else
playground [i][j].type=wood;
}
}
display(playground);
}
Why does this not work ? Do I understand it correct, that when you have a 2D array you need to pass consider it as a double pointer ?
Thanks