Question about array declaration/use

This is a discussion on Question about array declaration/use within the C++ Programming forums, part of the General Programming Boards category; I load a map from a file. I got it to work perfect thanks to Salem (^_^), that is the ...

Question about array declaration/use

I load a map from a file. I got it to work perfect thanks to Salem (^_^), that is the loading part works fine, and my game using the array works fine...... but only if I declare the array (it's global) like this:

Code:

byte Map[800] = {0};

if I declare it like this:

Code:

byte Map[800];

or

Code:

byte *Map = NULL;

(and then create it using new and delete it properly, of course)

then it doesn't work. What happens is that for some reason it has odd numbers in it. I don't think it has to do with the file loading code, because it loads the map fine if I add that = {0}; to the end.

What can I do to make the other two declarations work as well, and what's the main difference between byte Map[800] = {0}; and byte Map[800];? Even if I fill Map with zeros before loading it, it still creates problems...

I think the prob is in the loading map function, weird numbers is a symptom of creating a variable or array and not setting the values - consequently it will contain whatever junk value resides in that mem addr.

Your load map function should fill the whole MAP array with values you want and if there is left over space have your func zerofill the rest of the array. If you have junk you have probs.

I don't think the problem would be in any of the other variables (CamxOff, tCamx,x,y,etc), because the only time c ever becomes a problem is when the initialization to 0 is taken off. I tried memset(MAP, 0, 800 * sizeof (byte)); and it didn't change anything.