Compiler errors:
(In main)
Line 9:cannot convert char (*)[3] to char* for argument 1 to void showboard(char*, int, int)
(in showBoard)
Lines 16, 17, 21, 22, 26, 27:invalid types char[int] for array subscript

I don't understand these errors. I am trying to make a tic tac toe game, I have to initialize the board with '*'s. Right now I am merely trying to display the board with the '*'s. I have searched the forums and although there are a lot of tic tac toe threads none apply to me. Any help would be greatly appreciated, thanks!

void showBoard(char[], int, int);

int main() {
const int row = 3;
const int col = 3;
char game[row][col] = {{ '*', '*', '*'}, { '*', '*', '*'}, { '*', '*', '*'}};

showBoard(game, row, col);

return 0;
}
void showBoard(char game[], int row, int col) {
   cout << setw(5) << "1" << setw(6) << "2" << setw(6) << "\n"
        << setw(8) << "|" << setw(6) << "|" << "\n"
        << "A" << setw(3) << game[0][0] << setw(3) << "|" << setw(3) << game[0][1] 
        << setw(3) << "|" << setw(3) << game[0][2] << "\n"
        << setw(8) << "|" << setw(6) << "|" << "\n"
        << "  ------------------------------------\n"
        << setw(8) << "|" << setw(6) << "|" << "\n"
        << "B" << setw(3) << game[1][0] << setw(3) << "|" << setw(3) << game[1][1] 
        << setw(3) << "|" << setw(3) << game[1][2] << "\n"
        << setw(8) << "|" << setw(6) << "|" << "\n"
        << "  ------------------------------------\n"
        << setw(8) << "|" << setw(6) << "|" << "\n"
        << "C" << setw(3) << game[2][0] << setw(3) << "|" << setw(3) << game[2][1] 
        << setw(3) << "|" << setw(3) << game[2][2] << "\n"
        << setw(8) << "|" << setw(6) << "|" << "\n"
}

You need to declare showBoard like this: void showBoard(char[][3], int, int); Note that this hardcodes the size of the second dimension, but that will be okay if the board is always 3 by 3 (or indeed anything by 3).

In other words, you are trying to bind 2D array argument (line 9) with 1D array parameter declared in the line 13, then use 1D array parameter as 2D array in the function body (other lines).
Is it surprising that your compiler is surprised at these poetic licenses?

You need to declare showBoard like this: void showBoard(char[][3], int, int); Note that this hardcodes the size of the second dimension, but that will be okay if the board is always 3 by 3 (or indeed anything by 3).

That fixed it, thank you so much nucleon!

And thanks to ArkM for additional explanation!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.