当前位置: 动力学知识库 > 问答 > 编程问答 >

c - 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.

网友答案:

%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);
网友答案:

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) ;
分享给朋友:
您可能感兴趣的文章:
随机阅读: