0

I need to pass in a 2D array to a function but it's not working for me. It says "no matching function for call to display_board". I need to let the user define the size of the 2D array and pass it into a function. It should be very easy but I just couldn't get it working. Need help!! Thanks a lot!!

void display_board(int r, int c, char b[][c])
{
    for (int i=0; i<r; i++) {    //print out the board. Need to be deleted at last.
        for (int j=0; j<c; j++) {
            cout<<b[i][j];
        }
        cout<<endl;
    }

}



int main()
{
    int rows,columns,n;       
    cout<<"Enter rows: ";
    cin>>rows;
    cout<<"Enter columns: ";
    cin>>columns;
    cout<<"Enter n-in-a-row: ";
    cin>>n;


    char board_info[rows][columns]; //initialze the board
    for (int i=0; i<rows; i++) {
        for (int j=0; j<columns; j++) {
            board_info[i][j]='.';
        }
        cout<<endl;
    }


    display_board(rows, columns, board_info);//Says "no matching function for call to display_board"

    for (int i=0; i<rows; i++) {    //print out the board. Need to be deleted at last.
        for (int j=0; j<columns; j++) {
            cout<<board_info[i][j];
        }
        cout<<endl;
    }
}
user2817869
  • 158
  • 1
  • 2
  • 9

0 Answers0