1. non-lvalue error

/*****
Name:Zackery Breeland Date Assigned:April 7, 2009
Course:CSE 1233 Date Due:April 17, 2009

File Name: zlb12Lab8.c

Program Description:
To create a tick tack toe game against a computer.
*****/

Code:
#include <stdio.h>
#include <stdlib.h>

void Board();
void Winner();
int selection(char, int);

int boxArray;
int box1, box2;
char square;
char winner;
int Player = 0;

int main()
{
int x, y;
int box1 = 0;
int box2 = 0;
int Player;
int boxValue = 0;
char square[box1][box2];

Board();

/*Choose Square*/
while(winner = ' ')
{
printf("%c", winner);

if(Player == 1)
{
printf("X");
printf("Choose a square position:  ");
printf("Row:  ");
scanf("%d", &box1);
printf("Column:  ");
scanf("%d", &box2);

if(selection(square, Player) == 1)
Player = 1;
else
Player = 2;
}

else
{
printf("O");
printf("Choose a square position:  ");
printf("Row:  ");
scanf("%d", &box1);
printf("Column:  ");
scanf("%d", &box2);

if(selection(square, Player) == 1)
Player = 2;
else
Player = 1;
}
}

Board();
Winner();

return 0;
}

/*Selection*/
int selection(char square[box1][box2], int player)
{

if(square[box1 - 1][box2 - 1] == '\0' && (player == 1 || player == 0))
{
square[box1 -1][box2 - 1] = 'x';
return 0;
}

else if(square[box1 - 1][box2 - 1] == '\0' && player == 2)
{
square[box1 -1][box2 -1] == 'o';
return 0;
}

else
return 1;
}

/*Board*/
void Board()
{
printf("   |   |   \n");
printf("%c |%c |%c \n", square, square, square);
printf("   |   |   \n");
printf("___________\n");
printf("   |   |   \n");
printf("%c |%c |%c \n", square, square, square);
printf("   |   |   \n");
printf("___________\n");
printf("   |   |   \n");
printf("%c |%c |%c \n", square, square, square);
printf("   |   |   \n");
}

/*Who Won*/
void Winner()
{

if (square == 'x' && square = 'x' && square = 'x')
winner = 'x';
else if (square == 'x' && square == 'x' && square == 'x')
winner = 'x';
else if (square == 'x' && square == 'x' && square == 'x')
winner = 'x';
else if (square == 'x' && square == 'x' && square == 'x')
winner = 'x';
else if (square == 'x' && square == 'x' && square == 'x')
winner = 'x';
else if (square == 'x' && square == 'x' && square == 'x')
winner = 'x';
else if (square == 'x' && square == 'x' && square == 'x')
winner = 'x';
else if (square == 'x' && square == 'x' && square == 'x')
winner = 'x';
else if (square == 'o' && square == 'o' && square == 'o')
winner = 'o';
else if (square == 'o' && square == 'o' && square == 'o')
winner = 'o';
else if (square == 'o' && square == 'o' && square == 'o')
winner = 'o';
else if (square == 'o' && square == 'o' && square == 'o')
winner = 'o';
else if (square == 'o' && square == 'o' && square == 'o')
winner = 'o';
else if (square == 'o' && square == 'o' && square == 'o')
winner = 'o';
else if (square == 'o' && square == 'o' && square == 'o')
winner = 'o';
else if (square == 'o' && square == 'o' && square == 'o')
winner = 'o';
else
printf("CAT");

if(winner == 'x')
{
printf("x wins");
return;
}

if(winner == 'o')
{
printf("o wins");
return;
}
}

// After this point the program gives me a non-lvalue in assignment on line 118 in void Winner(). Does anyone know what is wrong. I just can't get this thing to work. 2. Code:
if (square == 'x' && square = 'x' && square = 'x')
You are doing assignment here, not comparing. Note the single equals sign instead of the double equals. Popular pages Recent additions Tags for this Thread

error, lvalue, non working, program problem 