Hermann Desu
Hermann Desu

Reputation: 11

printf not printing special characters

I'm trying to make a simple card game but after switching from Win 7 to Xubuntu 14.04 even the most simple things do not work anymore. I tried this for 3 days and still can't solve it. What happens is that the console is giving me 3 diamond question marks, for the code below.

#include <stdio.h>
#include <stdlib.h>
#define herz    "\xe2\x99\xa5"
#define karo    "\xe2\x99\xa6"
#define kreuz   "\xe2\x99\xa3"
#define pik     "\xe2\x99\xa0"

int main()
{
char ch = '0';
printf("%c%c%c%c",herz,karo,kreuz,pik);
return 0;
}

I tried this with the code:blocks console and the xubuntu one.

(xterm -T $TITLE -e and xfce4-terminal -T $TITLE -x)

Console LANG is en_US.UTF-8.

I tried several fonts and it didn't change a thing. I can type in special characters manually in the console but when C tries to print them it does not work.

Upvotes: 0

Views: 902

Answers (2)

Madhav Datt
Madhav Datt

Reputation: 1083

%c is used to print single characters. Since you are trying to print strings, use %s instead. Your print statement will be

wprintf("%s%s%s%s",herz,karo,kreuz,pik);

Upvotes: 3

Clifford
Clifford

Reputation: 93476

You have defined literal constant character strings where you need literal constant wide characters.

const wchar_t herz = L'\ue299a5';

You then need to print using wprintf() with the %lc format specifier:

wprintf("%lc%lc%lc%lc", herz, karo, kreuz, pikl) ;

Upvotes: 1

Related Questions