0

I dont understand why I can't print out this character array using the void function print_board which takes in the character array as parameter, initilize it and print it. Gives me [Error] invalid conversion from 'char' to 'char ()[8]' [-fpermissive] [Error] initializing argument 1 of 'void print_board(char ()[8])' [-fpermissive]

what am i missing or doing wrong here?

 #include <iostream>
 using namespace std;
 void print_board(char [8][8]);


 int main() {
 char board[8][8];
 print_board(board[8][8]);

return 0;
}


void print_board(char board[8][8])
{

for(int i = 0;i<8;i++)
    for(int j = 0; j<8; j++)
    {

    board[i][j] = '.';
    cout<<board[i][j];
    }



   }
igon
  • 2,841
  • 1
  • 19
  • 33

2 Answers2

0

You're passing board[8][8] which is of type char.

print_board expects an array of char[8] given your definition of the function.

Change the invocation to print_board(board);

igon
  • 2,841
  • 1
  • 19
  • 33
0

In the main function you are not passing the array properly plus function header should be like this

print_board(board); // This should be in main

void print_board(board[][8])
{
    // Do something
}

For more detail visit Passing a 2D array to a C++ function

Community
  • 1
  • 1
Shravan40
  • 6,849
  • 5
  • 21
  • 43