2d array function error?

Hi I'm trying to pass in a 2d array as the arguement to a function that takes a 2d array and I get an error,I thought that I had to include just one size of the second value(the width) but even when I do this I get an error both pieces of code won't work,can anybody tell me what I'm doing wrong?
Thanks



UPDATE*********************


it's ok guys I figure dout what I was doing wrong but I do have one question how come the output I get is a weird looking smiley face and a <


UPDATE********************

solved the solution guys that smiley face will always be a mystery haha but it's ok I figured out what I was trying to do =)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <iostream>

using namespace std;


void printBoard(char board[3][3]){

      for(int row = 0;row < 3; row++){

        for(int col = 0;col < 3;  col++){

             cout << board[row][col] << endl;
        }

      }

}

int main()
{

    char board[3][3];
    printBoard(board[0][3]);

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


#include <iostream>

using namespace std;


void printBoard(char board[][3]){

      for(int row = 0;row < 3; row++){

        for(int col = 0;col < 3;  col++){

             cout << board[row][col] << endl;
        }

      }

}

int main()
{

    char board[3][3];
    printBoard(board[][3]);

}



Last edited on
@adam2016

Garbage gets printed out, because you haven't filled the array with known data. Large numbers could be in the array, and the program doesn't know what to do with them.

Next problem, you are not passing the array to the function, correctly. You do not pass the sizes, just the name, as in printBoard(board);
Topic archived. No new replies allowed.