简体   繁体   中英

Trying to make a function call to fill character array but keep getting error?

I am writing a Tic Tac Toe game by using a 2-dimensionaly char-array to keep the game state, but the compiler is giving me this error:

cannot convert parameter 1 from 'char' to 'char [][3]' 1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast.

The code:

int main() {
    srand(int(time(0)));
    char Board[max_rows][max_cols];
    zerofill(Board[max_rows][max_cols]);
    int num=1,num2=1;
    for (int i=0;i<9;i++) {
        if (i%2==0) {
            MyTurn(Board[max_rows][max_cols],num,num2);
            MyTurn(Board[max_rows][max_cols],num,num2);    
            num++,num2++;
        }
        else
            TheirTurn (Board[max_rows][max_cols],num, num2);
            num++,num2++;
    }
    return 0;
}

What am I doing wrong?

There are numerous problems in this program, but I suspect the particular compiler error you are having is arising from the call to 'zerofill'. You haven't provided the declaration of the 'zerofill' function, but it is apparently written to accept char[][3], your board type. What you are passing to it is a single character. 'Board' is a pointer to a pointer to char. Board[x] is a pointer to char. Board[x][y] is a char.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM