How to print Unicode character in C encoded using UTF8?

I am trying to print a magnifying glass ( http://www.fileformat.info/info/unicode/char/1f50e/index.htm ) and I get this error:

[niko@dev1 ncurses]$ gcc -o utf8 -std=c99 $(ncursesw5-config --cflags --libs) utf8.c 
utf8.c: In function β€˜main’:
utf8.c:12:10: error: \ud83d is not a valid universal character
   printw("\ud83ddd0e\n");         // escaped Unicode 
          ^
[niko@dev1 ncurses]$ cat utf8.c
#include <locale.h>
#include <curses.h>
#include <stdlib.h>


int main (int argc, char *argv[])
{
  setlocale(LC_ALL, "");

  initscr();

  printw("\ud83ddd0e\n");         // escaped Unicode 

  getch();
  endwin();

  return EXIT_SUCCESS;
}

What is the problem? For example, if I have an encoding decimal number that is 55357 for a magnifying glass, how would I print it in printf on the ncurses screen? (without using wchar_t as it consumes a lot of memory)

+4
source share
4 answers

fileformat.info . \ud83d\udd0e. UTF-16, Java, C, GCC, , , escape- \u Unicode, .

\u ( ) 8 , U + 1F50E \U0001F50E. printf.


PS: - ~_~T~N, , setlocale -lncursesw, , .

+4

UTF-16 (\ud8..\udd..), UTF-8. , :

perl -e 'print pack("H*","d83ddd0e")' | iconv -f UTF-16 -t UTF-32 | hexdump -C

, U + 0001F50E. C, \U U.

"\U0001F50E"

, 55357 - (U + 1F50E), , UTF-16.

+1

, :

  • ?

    , .

  • , , 55357, printf ncurses? ( wchar_t, )

    . , , , ncurses (.. ncursesw) , , (wchar_t).

printw printf, . , printw

printw, wprintw, mvprintw mvwprintw . printf [. printf (3)]. , , printf , waddstr .

, , dictionary ( "", ). waddstr :

. waddch .

, "" , . waddch . , , . () , waddch ncurses (read: "UTF-8" ) , . X/Open Curses, Character Set PORTABILITY.

\u escape gcc UTF-8, , , ncurses. , , , printf, .

, , printw, wchar_t.

+1

putwchar (. http://www.cplusplus.com/reference/cwchar/putwchar/) wchar, , UTF-16 .

undefined. Unix VT-100, 7- ASCII. ( , isprint).

, ​​ freetype2 cairo + pango, .

-1

Source: https://habr.com/ru/post/1652109/


All Articles