Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Printing ASCII characters to the screen in C

Printing ASCII characters to the screen in C
Thread Tools
Dark_Lotus
Forum Regular
Join Date: Jun 2006
Status: Offline
Reply With Quote
Jun 10, 2007, 01:16 PM
 
I have programmed a Blackjack game and what to enhance the 'graphics' of it a little bit. I want to show the card faces by inserting the heart, spade, diamond, and clover characters. How do I print these characters to the screen?

I tried this, but nothing comes up.
#include <stdio.h>
main()
{
printf("\n %c \n", 003);
return 0;
}
Where the 003 is, I thought thats where the Decimal code for the character went. This was just a guess, so forgive me if I was way off.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 10, 2007, 01:31 PM
 
You have it right, except your character is nonsense. 003 means the character with the octal value 3, which in ASCII is "ETX - End Of Text." You'll either have to get the correct number equivalent for the character or just put the character itself there like so:

[codex]#include <stdio.h>

int main()
{
printf("\n %c \n", 'c');
return 0;
}[/codex]
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Dark_Lotus  (op)
Forum Regular
Join Date: Jun 2006
Status: Offline
Reply With Quote
Jun 10, 2007, 02:38 PM
 
Originally Posted by Chuckit View Post
You have it right, except your character is nonsense. 003 means the character with the octal value 3, which in ASCII is "ETX - End Of Text." You'll either have to get the correct number equivalent for the character or just put the character itself there like so:

[codex]#include <stdio.h>

int main()
{
printf("\n %c \n", 'c');
return 0;
}[/codex]
[codex]
#include <stdio.h>
int main()
{
int blah = 0x03;
printf("%c", blah);
printf("\n");
}[/codex]

This should work, however, the heart character does not show up. Are there some characters that the terminal cannot display?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 10, 2007, 02:54 PM
 
I'm a bit confused as to why you're expecting a heart. Are you using some special font in your Terminal? Because ASCII 3 is ETX, not normally a heart character, so nothing should be showing up.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
WJMoore
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jun 10, 2007, 11:43 PM
 
Its a heart in DOS, that char code won't display what you want in the Terminal, as you've seen. You want to use Unicode characters. These are UTF-8 sequences I got from the Character Palette. The following should help:

code:

#include <stdio.h>
int main()
{
printf("\n%s\n", "\xE2\x99\xA5 \xE2\x99\xA6 \xE2\x99\xA0 \xE2\x99\xA3 ");
return 0;
}
( Last edited by WJMoore; Jun 11, 2007 at 12:08 AM. )
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:38 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,