Thread: Trouble printing tic tac toe

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Heraklion, Greece, Greece
    Posts
    26

    Trouble printing tic tac toe

    Hello guys i have trouble printing tic tac toe display board.I am using putty to connect to my uni computers which run debian.
    Code:
    printf("\n");
    printf(" %c | %c | %c\n", a[0][0], a[0][1], a[0][2]);
    printf("---+---+---\n");
    printf(" %c | %c | %c\n", a[1][0], a[1][1], a[1][2]);
    printf("---+---+---\n");
    printf(" %c | %c | %c\n", a[2][0], a[2][1], a[2][2]);
    This is the way i use to print(the array includes 'X' and 'O' and in codeblocks it works the way i want but on terminal it doesnt.Any help appreciated.

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    What is the output of the program when you run it from putty?

  3. #3
    Registered User
    Join Date
    Nov 2012
    Location
    Heraklion, Greece, Greece
    Posts
    26
    Quote Originally Posted by c99tutorial View Post
    What is the output of the program when you run it from putty?
    it asks where to place the 'X' and the computer responds with 'O'.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Sounds like it has nothing to do with the code posted then.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    So in what way does it "not work"? By output I mean something like what it looks like and why it is wrong

    Code:
    .X.|...|...
    ---+---+---
    ...|.O.|...
    ---+---+---
    ...|...|...
    That is an example output of the program snippet you showed, given appropriate values for the array - i'll use '.' to represent spaces. So what's wrong with it?

  6. #6
    Registered User
    Join Date
    Nov 2012
    Location
    Heraklion, Greece, Greece
    Posts
    26
    Sorry,i found the problem.It is beacause i used '\0' for blank and it didnt work.Instead ' ' worked.If anyone could explain that would be nice.Thanks for the replys.

  7. #7
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Characters with values lower than 32 are control characters and trying to print them out may produce terminal-dependent behaviour. For example I notice that on Windows printing out a character with value 0 prints a space, but I don't see why all terminals would interpret it that way. If you want to print a space to the terminal, then print a space.

  8. #8
    Registered User
    Join Date
    Dec 2012
    Posts
    1
    Quote Originally Posted by Konstantinos View Post
    Sorry,i found the problem.It is beacause i used '\0' for blank and it didnt work.Instead ' ' worked.If anyone could explain that would be nice.Thanks for the replys.
    Well '\0' means null, I believe null is a character that can occupy a space. (I'd suggest printing it out to test)

  9. #9
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    By the way, isspace('\0') returns false, so at least the C standard library does not consider this character to be a valid space. It seems like only Windows considers it a valid space character. But like I said, if you want a space, then just print ' ' - what's the point of using something that only gives valid output on certain types of terminals when you can easily make it work on all terminals.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble Printing out Array
    By denZer in forum C Programming
    Replies: 6
    Last Post: 11-06-2011, 01:37 PM
  2. trouble printing linked list
    By deathrattle in forum C Programming
    Replies: 3
    Last Post: 12-02-2008, 05:33 PM
  3. Having trouble printing from an array
    By Sir Andus in forum C Programming
    Replies: 2
    Last Post: 10-30-2006, 01:48 PM
  4. trouble printing
    By dPmunky in forum C Programming
    Replies: 6
    Last Post: 11-18-2002, 02:43 PM
  5. Trouble Printing ASCII Character
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2002, 08:04 PM