Hi everyone! This is the code that I have written in order to print a tic-tac-toe board. For example, if input was this:
1 2 0
1 1 2
0 2 0

The board would be this:
X . O
X X .
O . O

However, I don't know how to use void instead without changing the behaviour of the program. I have tried adding the following:

void readBoard(int board[SIZE][SIZE]);
void printBoard(int board[SIZE][SIZE]); but I know I have done it wrong

//WITHOUT VOID

include <stdio.h>

int main (int argc, char *argv[]) {

int ROW[3] [3];
int i, j;

printf("Please enter the board:\n");
for (i=0; i<3; i++) {
    for (j=0; j<3; j++) {
    scanf("%d", &ROW[i] [j]);
}    


}

printf("Here is the board:\n\n");

for (i=0; i<3; i++) {
    for (j=0; j<3; j++) {

        if (ROW[i] [j]==0) {
        printf("O ");
        }

        else if (ROW[i] [j]==1) {
        printf("X ");
        }

        else if (ROW[i] [j]==2) {
        printf(". ");
        }

        if (j==2) {
        printf ("\n");
        }

    }   

}

return 0;

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//WITH VOID

include <stdio.h>
#define SIZE 3

void readBoard(int board[SIZE][SIZE]);
void printBoard(int board[SIZE][SIZE]);

int main (int argc, char *argv[]) {
int BOARD[SIZE] [SIZE];
readBoard (BOARD,SIZE);
printBoard (BOARD,SIZE);
return 0;
}

printf("Please enter the board:\n");

void readBoard (int BOARD{] [SIZE], int

int i,j;
for (i=0; i<3; i++) {
    for (j=0; j<3; j++) {
       scanf("%d", &BOARD[i] [j]);
}   


}

printf("Here is the board:\n\n");

for (i=0; i<3; i++) {
for (j=0; j<3; j++) {

        if (BOARD[i] [j]==0) {
        printf("O ");
        }

        else if (BOARD[i] [j]==1) {
        printf("X ");
        }

        else if (BOARD[i] [j]==2) {
        printf(". ");
        }

        if (j==2) {
        printf ("\n");
        }

    }  

}
//There is a winner if noughts or crosses gets 3 in a row or column, diregard diagonals so 3 in a diagonal is not counted as a win.

       int winner(int board[SIZE][SIZE]);
        for (i=0; i<3; i++) {
            for (j=0; j<3; j++) {
                if ((board [0] [0]=X) && (board [0] [1]=X) && (board [0] [2]=X) {                      
                    printf("Noughts win\n");                                                                              

                } else if ((board [1] [0]=X) && (board [1] [1]=X) && (board [1] [2]=X) {
                    printf("Noughts win\n");
                } else if ((board [2] [0]=X) && (board [2] [1]=X) && (board [2] [2]=X) {
                    printf("Noughts win\n");
                }

return 0;

}

~~~~~~~~
Thank you for any help you can offer me

Recommended Answers

All 2 Replies

correct the brackets of the functions otherwise you can't tell when does a functions start and end

Please click the Code button in the editor toolbar when attempting to post code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.