简体   繁体   中英

Add smiley face in c

I am trying to print smiley face using C. My program is

#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;

    }
}

I am using Ubuntu Terminal. It is working fine in Windows but not in Ubuntu . Please help. Thanks in advance

If you want to output a smiley face you cannot use the ascii characters. Again, look at that ascii man page for the complete set of available characters.

However you can use the UTF-8 encoding, if your terminal support it. The code snippet below print a smiley face with sunglasses on my terminal:

#include <stdio.h>

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

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

Another possibility is to use

printf("\u263A\n");

According to his UTF-8 page which report the C/C++/Java source code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM