Source Code File 04-11_unicode

04-11_unicode.c

#define _XOPEN_SOURCE_EXTENDED 1
#include <ncurses.h>
#include <locale.h>

int main()
{       
    cchar_t heart = {
        A_NORMAL,
        L"\u2665"
    };
    
    /* activate Unicode character set */
    setlocale(LC_CTYPE,"en_US.UTF-8");
    
    initscr();

    addstr("I ");
    add_wch(&heart);
    addstr(" Ncurses");
    refresh();
    getch();

    endwin();
    return 0;
}

Output Screenshot

Notes

* Remember that you need to link with the ncursesw library instead of ncurses. Even then, not every Ncurses installation supports these features. If not, use your distro's package manager to install wide-character Ncurses.

* The heart may not show up, depending on how the Unicode character set is implemented on the terminal.

* For more details on Unicode programming in C, refer to my blog.