Function return value conflict

This is a discussion on Function return value conflict within the C Programming forums, part of the General Programming Boards category; I'm writing a tic tac toe program and I have a problem with the function that determines whether or not ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    26

    Function return value conflict

    I'm writing a tic tac toe program and I have a problem with the function that determines whether or not there is a winner. When I try to compile, it gives me an error saying there are conflicting types of the function. All return values should be a character, so I can't figure out what the problem is.

    Here is the function:

    Code:
    char checkWinner (char cell[])
    {
            if(cell[0] == cell[1] == cell[2])
            {
                    if(cell[0] != ' ')
                    {
                    return cell[0];
                    } else return ' ';
            } else if(cell[3] == cell[4] == cell[5])
            {
                    if(cell[3] != ' ')
                    {
                    return cell[3];
                    } else return ' ';
            } else if(cell[6] == cell[7] == cell[8])
            {
                    if(cell[6] != ' ')
                    {
                    return cell[6];
                    } else return ' ';
            } else if(cell[0] == cell[3] == cell[6])
            {
                    if(cell[0] != ' ')
                    {
                    return cell[0];
                    } else return ' ';
            } else if(cell[1] == cell[4] == cell[7])
            {
                    if(cell[1] != ' ')
                    {
                    return cell[1];
                    } else return ' ';
            } else if(cell[2] == cell[5] == cell[8])
            {
                    if(cell[2] != ' ')
                    {
                    return cell[2];
                    } else return ' ';
            } else if(cell[0] == cell[4] == cell[8])
            {
                    if(cell[0] != ' ')
                    {
                    return cell[0];
                    } else return ' ';
            } else if(cell[2] == cell[4] == cell[6])
            {
                    if(cell[2] != ' ')
                    {
                    return cell[2];
                    } else return ' ';
            } else return 'd';
    
    
    }

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    Please post the exact error message including line number.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    26
    p1.c:121: error: conflicting types for 'checkWinner'


    And the error is on line 121, which is actually the line:

    char checkWinner(char cell[])

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    Quote Originally Posted by cashmerelc View Post
    p1.c:121: error: conflicting types for 'checkWinner'


    And the error is on line 121, which is actually the line:

    char checkWinner(char cell[])
    You must have a prototype of checkWinner() somewhere that doesn't match this. The exact location of this other definition was probably printed by the compiler.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    if(cell[0] == cell[1] == cell[2])
    do you mean this to mean that all these are equal?

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    26
    Code:

    if(cell[0] == cell[1] == cell[2])

    do you mean this to mean that all these are equal?

    Yeah, do I need to use the && operator between them?

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    Quote Originally Posted by cashmerelc View Post
    Yeah, do I need to use the && operator between them?
    Yeah. I missed that one:

    Code:
    if(cell[0] == cell[1] && cell[1] == cell[2])

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 12:49 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21