So, basically what I'm trying to do is a Tic Tac Toe game for a project. I started with making 3 1-D Char Arrays to represent the game's bord. the code below compares the Arrays data to try and figure out if any of the winning possibilites were achieved by option x or y. There is a variable set to 0, this variable will change to 1 if player1 won and will change to 2 if player2 won, if it remains 0 then it's a draw. Now, there's 16 errors of Error C2446 '==': no conversion from 'const char [2]' to 'int'.

#include <stdio.h>
#include <conio.h>
#include <string.h>
//This function is made to check the result of the round, either one of the players win or it's a draw. It also states who is the winner or if it's a draw.
int main()
{
    int playerwon = 0;//This variable is to indicate which player won, if it's = 1 then Player1 won, if 2 then player2 won, if it remains 0 then draw.
    char board1[4] = {'-','-','-','\0'};
    char board2[4] = { '-','-','-','\0'};
    char board3[4] = { '-','-','-','\0'};

    //Coloumns win check for X, Player 1.
    if (board1[0] == board2[0] && board3[0] == board2[0] && board3[0] == 'x')
    {
        playerwon = 1;
    }
    else if (board1[1] == board2[1] && board3[1] == board2[1] && board3[1] == 'x')
    {
        playerwon = 1;
    }
    else if (board1[2] == board2[2] && board3[2] == board2[2] && board3[2] == 'x')
    {
        playerwon = 1;
    }
    //Rows win check for X, Player 1.
    else if (board1[0] == board1[1] && board1[1] == board1[2] && board1[2] == 'x')
    {
        playerwon = 1;
    }
    else if (board2[0] == board2[1] && board2[1] == board2[2] && board2[2] == 'x')
    {
        playerwon = 1;
    }
    else if (board3[0] == board3[1] && board3[1] == board3[2] && board3[2] == 'x')
    {
        playerwon = 1;
    }
    //Diagonals win check for X, Player 1.
    else if (board1[0] == board2[1] && board2[1] == board3[2] && board3[2] == 'x')
    {
        playerwon=1;
    }
    else if (board1[2] == board2[1] && board2[1] == board3[0] && board3[0] == 'x')
    {
        playerwon = 1;
    }
    //Coloumns win check for Y, Player 2.
    else if (board1[0] == board2[0] && board3[0] == board2[0] && board3[0] == 'y')
    {
        playerwon = 2;
    }
    else if (board1[1] == board2[1] && board3[1] == board2[1] && board3[1] == 'y')
    {
        playerwon = 2;
    }
    else if (board1[2] == board2[2] && board3[2] == board2[2] && board3[2] == 'y')
    {
        playerwon = 2;
    }
    //Rows win check for Y, Player 2.
    else if (board1[0] == board1[1] && board1[1] == board1[2] && board1[2] == 'y')
    {
        playerwon = 2;
    }
    else if (board2[0] == board2[1] && board2[1] == board2[2] && board2[2] == 'y')
    {
        playerwon = 2;
    }
    else if (board3[0] == board3[1] && board3[1] == board3[2] && board3[2] == 'y')
    {
        playerwon = 2;
    }
    //Diagonals win check for Y, Player 2.
    else if (board1[0] == board2[1] && board2[1] == board3[2] && board3[2] == 'y')
    {
        playerwon = 2;
    }
    else if (board1[2] == board2[1] && board2[1] == board3[0] && board3[0] == 'y')
    {
        playerwon = 2;
    }
    //Printing the result of the round!
    if (playerwon = 1) {
        printf("Player one won this round!");
    }
    else if (playerwon = 2) {
        printf("Player two won this round!");
    }
    else if (playerwon = 0) {
        printf("This round is a draw!");
    }
    else {
        printf("Error calculating the round result!");
    }
    return 0;
}

I have solved the problem, basically what I had to do is

   if (playerwon = 1) {
        printf("Player one won this round!");
    }
    else if (playerwon = 2) {
        printf("Player two won this round!");
    }
    else if (playerwon = 0) {
        printf("This round is a draw!");

Change the playerwon = to Playerwon==, it worked just fine.

use a short code

#include <stdio.h>

int main(){

    // use int array of 9 cells
    // 0 means blank
    // 1 means O (player 1)
    // -1 means X (player 2)
    int board[9] = {    1,   1,   -1, 
                        -1,  1,   1, 
                        1,   -1,  -1        };  

    int row1 = board[0] + board[1] + board[2];
    int row2 = board[3] + board[4] + board[5];
    int row3 = board[6] + board[7] + board[8];

    int col1 = board[0] + board[3] + board[6];
    int col2 = board[1] + board[4] + board[7];
    int col3 = board[2] + board[5] + board[8];

    int dia1 = board[0] + board[4] + board[8];
    int dia2 = board[2] + board[4] + board[6];

    int board_sum[8] = {row1, row2, row3, col1, col2, col3, dia1, dia2};
    int i=0;
    int has_winner=0;

    for(i=0;i<8;i++){
        if (abs(board_sum[i])==3){  
        // if absolute value of any of the sum is 3, it means we have a winner
            has_winner=1;

            if (board_sum[i]>0){
                printf("Player 'O' won this round!");
            } else{
                printf("Player 'X' won this round!");
            }
            break;
        }  
    }
    if (has_winner==0){ printf("This round is a draw!");}

    return 0;
}
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.