2d array printing garbage on last line

Hi all, can't figure out why my array is printing garbage on the last line :

This is my function, takes the array and lets me print it out when ever I call it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int gridmap (char grid[5][5])
{
       int row;
       int column;
    
        for (row = 0; row < 5; row++)
    {
    {
    	for (column = 0; column < 5; column++)
    		
            cout << grid[row][column];
            cout << endl;
            }
            }
  
};
Fix your braces and indentation.
Did you put garbage in the array?
Sorry my bad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int gridmap (char grid[5][5])
{
       int row;
       int column;
    
        for (row = 0; row < 5; row++)
    {
    
    	for (column = 0; column < 5; column++)
    	
    		
            cout << grid[row][column];
            cout << endl;
        
            
    }
  
};
Still get the same garbage on the last line
This is my array:
1
2
3
4
5
6
7
8
9
  char grid[5][5]=
    {
        {'o','o','o','o','o'},
        {'o','o','o','o','o'},
        {'o','o','.','o','o'},
        {'o','o','o','o','o'},
        {'o','o','o','o','o'},
        
    };
If you're really passing that array to the function, it should work.
Your indentation is still way off.

1
2
3
4
5
6
7
8
9
int gridmap (char grid[5][5])
{
  for (int row = 0; row < 5; row++)
  {  
    for (int column = 0; column < 5; column++)		
         cout << grid[row][column];
    cout << endl;    
  }
}


Using misleading indentation only provokes errors of all sorts.
Last edited on
Thanks for the help on the indentation, I have no idea why it's spitting out 7 numbers each time I run the program 2686684... Quite strange indeed, seems to be the same each time I run it.
It's probably due to memory corruption in another part of your program.
Only other part of my program is cout << gridmap(grid);

and cin.get();
Last edited on
The last line is garbage because you print the return value of gridmap(grid) but you never return anything from that function so all you get is some garbage value.
Last edited on
aha! That's perfect. Thanks very much for the help guys, really appreciate, had me stumped did that one!
Topic archived. No new replies allowed.