繁体   English   中英

如何创建一个条件来返回 C 中其他函数的某些内容

[英]How can I create a condition that return something of the other function in C

我正在尝试用 C 做一个滴答游戏,所以我应该改变 checkStatus 函数。 我将向您展示我遇到问题的代码部分:

int checkStatus(char board[][3]) {

    int status = -1;
    **int j, i;
    if (board = ([][][],[][][],[][][]));
    return check Status(tab0);**

    return status;
}

int main(){

    char tab0[][3] = {{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}};

    char tab1[][3] = {{'X','X','X'},{'O','O',' '},{' ',' ',' '}};

    char tab2[][3] = {{'O','X','X'},{'X','O','O'},{' ',' ','O'}};

    char tab3[][3] = {{'O','X','X'},{'X','O','O'},{'O','X','X'} };

    char tab4[][3] = {{' ',' ',' '},{'X','O','X'},{' ',' ',' '}};


    printf("Calculated Status: %i\n", checkStatus(tab0));

    printf("Expected status for board0: 0\n\n");

return 0;
}

如您所见,粗体部分是我尝试做的,但它没有运行(我是新手)。 我想要做的是一个条件,如:

“如果板子没有'X'或'0',则状态必须返回数字0(根据主函数)。我想在不将printf放入“verificaStatus”函数中的情况下进行。

#include <string.h>

int checkStatus(char (*board)[3][3]) 
{
    int status = -1;

    if(!memchr(board, '0', sizeof(*board)) && 
       !memchr(board, 'X', sizeof(*board))) status = 0;

    return status;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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