Thread: non-lvalue error

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Question 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[3][3];
    int box1, box2;
    char square[3][3];
    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[3][3], 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[3][3], 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[0][0], square[0][1], square[0][2]);
    	printf("   |   |   \n");
    	printf("___________\n");
    	printf("   |   |   \n");
    	printf("%c |%c |%c \n", square[1][0], square[1][1], square[1][2]);
    	printf("   |   |   \n");
    	printf("___________\n");
    	printf("   |   |   \n");
    	printf("%c |%c |%c \n", square[2][0], square[2][1], square[2][2]);
    	printf("   |   |   \n");
    }
    
    /*Who Won*/
    void Winner()
    {
    
    	if (square[0][0] == 'x' && square[0][1] = 'x' && square[0][2] = 'x')
    		winner = 'x';
    	else if (square[1][0] == 'x' && square[1][1] == 'x' && square[1][2] == 'x')
    		winner = 'x';
    	else if (square[2][0] == 'x' && square[2][1] == 'x' && square[2][2] == 'x')
    		winner = 'x';
    	else if (square[0][0] == 'x' && square[1][0] == 'x' && square[2][0] == 'x')
    		winner = 'x';
    	else if (square[0][1] == 'x' && square[1][1] == 'x' && square[2][1] == 'x')
    		winner = 'x';
    	else if (square[0][2] == 'x' && square[1][2] == 'x' && square[2][2] == 'x')
    		winner = 'x';
    	else if (square[0][0] == 'x' && square[1][1] == 'x' && square[2][2] == 'x')
    		winner = 'x';
    	else if (square[0][2] == 'x' && square[1][1] == 'x' && square[2][0] == 'x')
    		winner = 'x';
    	else if (square[0][0] == 'o' && square[0][1] == 'o' && square[0][2] == 'o')
    		winner = 'o';
    	else if (square[1][0] == 'o' && square[1][1] == 'o' && square[1][2] == 'o')
    		winner = 'o';
    	else if (square[2][0] == 'o' && square[2][1] == 'o' && square[2][2] == 'o')
    		winner = 'o';
    	else if (square[0][0] == 'o' && square[1][0] == 'o' && square[2][0] == 'o')
    		winner = 'o';
    	else if (square[0][1] == 'o' && square[1][1] == 'o' && square[2][1] == 'o')
    		winner = 'o';
    	else if (square[0][2] == 'o' && square[1][2] == 'o' && square[2][2] == 'o')
    		winner = 'o';
    	else if (square[0][0] == 'o' && square[1][1] == 'o' && square[2][2] == 'o')
    		winner = 'o';
    	else if (square[0][2] == 'o' && square[1][1] == 'o' && square[2][0] == '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. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Code:
    if (square[0][0] == 'x' && square[0][1] = 'x' && square[0][2] = 'x')
    You are doing assignment here, not comparing. Note the single equals sign instead of the double equals.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

Tags for this Thread