I have a function "printWorld" in a class that prints a 2D array called "world". Whenever I use this function and run my program in the terminal it appears to print the array but then a massive amount of random numbers and at the end says "Segmentation Fault" and closes my program. As soon as I take this function out of my code though everything works just fine.
void printWorld()
{
for(int r = 0; r <= (2*WORLD_SIZE + 1); r++)
{
for(int c = 0; r <= (2*WORLD_SIZE + 1); c++)
cout << world[r][c];
cout << endl;
}
}
This is how the function is written in the class
game.printWorld();
This is how I'm calling the function.
This is what is showing in termninal
If it helps I have this array initialized all to 0.
<=as the condition in aforloop i smell a bugfor(int c = 0; r <= (2*WORLD_SIZE + 1); c++)is an infinite loop (assuming the condition is true once, sincernever changes in the scope of that loop). Did you meanc <= ...?