在c中添加笑脸

时间:2016-04-05 08:30:51

标签: c ubuntu

我正在尝试用C打印笑脸。我的程序是

#include <stdio.h>

int main()
{
    int x;
    char i=1;
    for(x=1;x<=800;x++) 
    {
        printf(" %c ", i); 
        if(x==800)
        printf("\n"); 
        if(x==800)
        break;

    }
}

我正在使用Ubuntu终端。它在Windows中正常工作,但在Ubuntu中却没有。请帮忙。提前致谢

1 个答案:

答案 0 :(得分:2)

如果要输出笑脸,则无法使用ascii字符。 再次,请查看ascii man page以获取完整的可用字符集。

但是,如果您的终端支持,您可以使用UTF-8编码。 下面的代码片段在我的终端上打印带笑脸的笑脸:

#include <stdio.h>

int main()
{
 char s[] = { 0xf0, 0x9f, 0x98, 0x8e, 0};

 printf("%s\n", s);
}

另一种可能性是使用

printf("\u263A\n");

根据报告C/C++/Java源代码

UTF-8页面