Thread: if else problem

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    46

    if else problem

    i am having trouble trying to convert a 0 or 1 into an X or O.
    here is my print function of the program
    Code:
    char print(int row1col1, int row1col2, int row1col3)
    {
       char X;                
       char O;     
                 
       if (row1col1 == 1) 
          row1col1 = X;          
       else row1col1 = O;   
                                 
       if (row1col2 == 1)            
          row1col2 = X;          
       else row1col2 = O;
                              
       if (row1col3 == 1)
          row1col3 = X;
       else row1col3 = O;   
                           
       printf("\n|%s| |%s| |%s|", row1col1, row1col2, 
       row1col3);
    }
    when i dont try and convert, i get a randomly selected 0 and 1's so i know i am creating it right but when i use the if else above i get a
    |(null)| |(null)| |(null)| as output. so please help.....

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    X and O are undefined. Maybe try:
    Code:
       char X='X';                
       char O='O';
    Or, simply do:
    Code:
       if (row1col1 == 1) 
          row1col1 = 'X';          
       else row1col1 = 'O';
    etc.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    row1col1, row1col2, row1col3 aren't strings but the printf makes them out to be.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    yea that worked thanks everyone

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM