Hello all!
So... I have wrote a function to respond in a certain way based on what part of the map the player is located (each represented by a number in a dynamically allocated 2-D array), but the program stops working after the switch statement has run (the proof being that it runs the switch case and then encounters an error and stops working (a segmentation fault possibly, but I don't know for sure)). The function is below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void MapFunctions::EquateTextPrint(){
switch(Map[locx][locy]){
case 1:
cout << "You can move: ";
if(Map[locx][locy+1]){cout << "East";}
if(Map[locx][locy-1]){cout << "West";}
if(Map[locx+1][locy]){cout << "North";}
if(Map[locx-1][locy]){cout << "South";}
break;
default:
cout << "Something is wrong with this map.....";
break;
};
cout << "This works";
};
I know that it is the switch caase because it will run the print "You can move: EastNorth" and then stop working. I'm probably missing the obvious, but could someone tell me what is wrong with this code, please?
Oh yes... if it helps, the message on the console displays "Process returned -1073741819 (0xC0000005)"
Ah that probably is the issue. locy - 1 and locy + 1 both have potential to access memory that isn't allocated for your array. Would cause a crash most of the time.