如何修复Wint转换警告?

时间:2018-03-22 21:19:01

标签: c

这是我开始的一个ticktacktoe游戏的片段。当我编译它时,会弹出Wint转换警告,说明clear_table(board);和display_table(board);从没有强制转换的指针制作整数。我在C上真的很陌生,我不知道如何解决这个问题。另外,我根本不允许更改主要功能。

#include <stdio.h>
#define SIZE 3

void display_table(char board);
void clear_table(char board);

int main()
{
    char board[SIZE][SIZE];
    int row, col;

    clear_table(board);

    display_table(board);

    return 0;
}

void clear_table(char board) {
    int row = 0, col = 0;
    for(row = 0; row < SIZE; row++) {
        for(col = 0; col < SIZE; col++) {
            board = '_';
        }
    }

    return;
}

void display_table(char board) {
    printf("The current state of the game is: \n");
    int row = 0, col = 0;
    for(row = 0; row < SIZE; row++) {
        for(col = 0; col < SIZE; col++) {
            printf("%c ", board);
        }
        printf("\n");
    }

    return;
}

请帮帮忙?

1 个答案:

答案 0 :(得分:1)

将数据板char board[SIZE][SIZE]作为数组传递给函数,并通过数组下标运算符传递给函数访问元素:[][]

#include <stdio.h>
#define SIZE 3

void display_table(char  board[][SIZE]);
void clear_table(char  board[][SIZE]);

int main(void)
{
    char board[SIZE][SIZE];
    int row, col;

    clear_table(board);

    display_table(board);

    return 0;
}

void clear_table(char  board[][SIZE]) {
    int row = 0, col = 0;   
    for(row = 0; row < SIZE; row++) {
        for(col = 0; col < SIZE; col++) {
            board[row][col]= '_';
        }   
    } 
    return;
}

void display_table(char board[][SIZE]) {
    printf("The current state of the game is: \n");
    int row = 0, col = 0;
    for(row = 0; row < SIZE; row++) {
        for(col = 0; col < SIZE; col++) {
            printf("%c ", board[row][col]);           
        }
        printf("\n");   
    }
    return;
}

输出:

The current state of the game is:                                                                                                            
_ _ _                                                                                                                                        
_ _ _                                                                                                                                        
_ _ _                                                                                                                                        
相关问题