Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何修复Wint转换警告?_C - Fatal编程技术网

C 如何修复Wint转换警告?

C 如何修复Wint转换警告?,c,C,这是我开始的滴答声游戏的一个片段。当我编译它时,Wint转换警告弹出,说clear_tableboard;展示"台板",;正在从指针生成整数,无需强制转换。我是C的新手,我不知道如何解决这个问题。另外,我根本不允许更改主功能 #include <stdio.h> #define SIZE 3 void display_table(char board); void clear_table(char board); int main() { char board[SIZE]

这是我开始的滴答声游戏的一个片段。当我编译它时,Wint转换警告弹出,说clear_tableboard;展示"台板",;正在从指针生成整数,无需强制转换。我是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;
}
请提供帮助?

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


提示:字符板只能保存一个字符值。然而,你可以用一个字符*@usr2564301,不,是2D数组,这是不同的。board是一个2D字符数组,而不是一个字符:虽然离一个字符还有一个世界。clear_表可以被一个很好的“MemsBoard”,一个“SIZE”,SizeThat代替。谢谢!现在更有意义了@Jean Françoisfar感谢您的评论!这是非常正确的,这是很好的优化程序!我不想这样做是为了纠正board='';缺陷再次感谢你指出这一点!是的,OP的任务可能没有那么远。
#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:                                                                                                            
_ _ _                                                                                                                                        
_ _ _                                                                                                                                        
_ _ _