-2

Now I make the for statements as follow,

for (int i = 0; i < 256; i ++) {
            printf("%5c", i);
 }

And I want to get the real content with ASCII

Eric Tsui
  • 1,924
  • 12
  • 21
Zhi Chang
  • 35
  • 5
  • 2
    what do you mean by "real content"? – Pynchia Jul 06 '15 at 09:19
  • such as a smile character – Zhi Chang Jul 06 '15 at 09:24
  • 3
    I hope you know that ascii does not contain a single smile face character. So what is the actual content you want to output. The basic version of a smiley in ascii would be `:-)` or `:)`. I think there is a character from japan that looks like a smiley. In some fonts you also have smileys as a character. Any other smileys are done by showing icons instead of characters. – ikrabbe Jul 06 '15 at 09:24
  • like this image: [img](http://imgsrc.baidu.com/forum/pic/item/5e9ad5628535e5dd3167308c74c6a7efcf1b62f6.jpg) – Zhi Chang Jul 06 '15 at 09:41
  • Those are MS-DOS OEM characters. The particular output depends on your terminal. Under Windows, run from the default command prompt, I indeed get "smile faces" (and lots of other characters) from your code, so I don't see the problem. – Jongware Jul 06 '15 at 10:18

2 Answers2

2

Provided your terminal is set to UTF-8 encoding, this piece of code

#include <stdio.h>

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

 printf("%s", s);
}

outputs a smiley with sunglasses.

To find out how to encode other UNICODE characters use the top navigation bar on the page (or the previous/next angle brackets)

Pynchia
  • 10,996
  • 5
  • 34
  • 43
-1

You can try to use Unicode instead of ASCII

This's an example on Swift

let dog = String(UnicodeScalar(0x1F436))
println(dog)

for codeUnit in dog.utf8 {
    print("\(codeUnit) ")
}

Swift docs

Tikhonov Aleksandr
  • 13,945
  • 6
  • 39
  • 53
  • Thanks, but I want do it in C-Language – Zhi Chang Jul 06 '15 at 09:43
  • I'm not sure about C-language, but you can use this itf8 codes of smile for input: 240 159 144 182. Actually I think it's impossible use Unicode symbols in program is written by C – Tikhonov Aleksandr Jul 06 '15 at 10:02
  • 1
    @TikhonovAlexander: uh, *what*? I have been doing the impossible for some years, then. Even if you mean one cannot use *literal* Unicode characters, well, that may depend on the compiler. See e.g. [Unicode encoding for string literals in C++11](http://stackoverflow.com/q/6796157/2564301) – Jongware Jul 06 '15 at 10:23
  • @Jongware yeas I meant it – Tikhonov Aleksandr Jul 06 '15 at 10:36