How to get ncurses to correctly display UTF-8 characters in C?

I have a program written in C using ncurses. It allows the user to enter and display it. It does not display correctly if the user enters utf8 characters.

I saved the user characters entered in the file. And I cat this file directly in Shell, it displays correctly.

I searched stackoverflow and google and tried several methods, such as link with ncursesw, to display incorrectly.

And I ldd /usr/bin/screen : libncurses.so.5 => /usr/lib64/libncurses.so.5

screen can correctly display what user input.

How to get ncurses to correctly display UTF-8 characters?

What is the general way to display UTF-8 characters in C using ncurses?

+8
c linux screen ncurses
source share
1 answer

Before initializing ncurses, you need to call setlocale(LC_CTYPE, ""); (with locale configuration based on UTF-8). You also need to make sure your ncurses are really built with broad char support ("ncursesw"), but on modern distributions this is the default / only assembly.

+14
source share

All Articles