|
|
Printing ASCII characters to the screen in C
|
|
|
|
Forum Regular
Join Date: Jun 2006
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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'."
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jun 2006
Status:
Offline
|
|
Originally Posted by Chuckit
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?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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'."
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status:
Offline
|
|
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 Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|