Skip to main content
added 219 characters in body
Source Link
Mud
  • 29.2k
  • 12
  • 64
  • 100

That is not initializing the array, it's printing it. Given that it's not initialized, it prints garbage.

Instead of:

 cout << map[row][col]map[row][col]; 

you want:

map[row][col] = <some initializtion value, probably a space, e.g. ' '>'*'; 

That will set the initial value for each cell in your array, which is to say, initialize it.

You can also do this at the same time you define the array using C++'s array initializer syntax, but your approach is better.

That is not initializing the array, it's printing it. Given that it's not initialized, it prints garbage.

Instead of:

 cout << map[row][col] 

you want:

map[row][col] = <some initializtion value, probably a space, e.g. ' '> 

That is not initializing the array, it's printing it. Given that it's not initialized, it prints garbage.

Instead of:

 cout << map[row][col]; 

you want:

map[row][col] = '*'; 

That will set the initial value for each cell in your array, which is to say, initialize it.

You can also do this at the same time you define the array using C++'s array initializer syntax, but your approach is better.

Source Link
Mud
  • 29.2k
  • 12
  • 64
  • 100

That is not initializing the array, it's printing it. Given that it's not initialized, it prints garbage.

Instead of:

 cout << map[row][col] 

you want:

map[row][col] = <some initializtion value, probably a space, e.g. ' '>