简体   繁体   中英

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

I'm trying to make a game of ticking in C, so I should just change the checkStatus function. I'll show you the part of the code I'm having trouble with:

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;
}

As you can see, the bold part is what I tried to do, but it doesn't run (I'm new to this). What I want to do is a condition like:

"If the board has no 'X' or '0', the status must return the number 0 (according to the main function). I want to do it without putting printf in the "verificaStatus" function.

#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;
}

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