Thread: if else problem

  1. #1
    Registered User
    Join Date
    Oct 2008

    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
    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, 
    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
    On me hyperplane
    X and O are undefined. Maybe try:
       char X='X';                
       char O='O';
    Or, simply do:
       if (row1col1 == 1) 
          row1col1 = 'X';          
       else row1col1 = 'O';

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

  4. #4
    Registered User
    Join Date
    Oct 2008
    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, 10: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
Website Security Test