ocodo ocodo - 1 year ago 83
C Question

Adding Unicode/UTF8 chars to a ncurses display in C

I'm attempting to add wchar_t Unicode characters to an ncurses display in C.

I have an array:

wchar_t characters[]={L'\uE030', L'\uE029'}; // containing 2 thai letters, for example

And I later try to add a wchar_t from the array to the ncurses display with:


To provide a bit more info, doing this with ASCII works ok, using:

char characters[]={'A', 'B'};

// and later...


To setup the locale, I add the include...

#include <locale.h>

// in main()

The ncurses include is:

#include <ncurses.h>

Compiling with :

(edit: added c99 standard, for universal char name support.)

gcc -o ncursesutf8 ncursesutf8.c -lm -lncurses -Wall -std=c99

I get the following compilation warning (of course the executable will fail):

ncursesutf8.c:48: warning: implicit declaration of function ‘add_wch’

I've tried just using
which appears to be macro'ed to work with wchar_t but when I do that the Unicode chars do not show up, instead they show as ASCII chars instead.

Any thoughts?

I am using OS X Snow Leopard, 10.6.6

Edit: removed error on
wchar_t []
assignment to use
instead of
I've also updated the compiler settings to use C99 (to add universal char name support). both changes do not fix the problem.

Still no answers on this, does anyone know how to do Unicode ncurses
(add_wchar?) ?! Help!

Answer Source

The wide character support is handled by ncursesw. Depending on your distro, ncurses may or may not point there (seemingly not in yours).

Try using -lncursesw instead of -lncurses.

Also, for the locale, try calling setlocale(LC_ALL, "")

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download