In a C program for Linux, with ncursesw
and form
, I need to read the string stored in a field
, with support for UTF-8 characters. When ASCII only is used, it is pretty simple, because the string is stored as an array of char
:
char *dest;
...
dest = field_buffer(field[0], 0);
If I try to type a UTF-8 and non-ASCII character in the field with this code the character does not appear and it is not handled. In this answer for UTF-8 it is suggested to use ncursesw
. But with the following code (written following this guide)
#define _XOPEN_SOURCE_EXTENDED
#include <ncursesw/form.h>
#include <locale.h>
int main()
{
...
setlocale(LC_ALL, "");
...
initscr();
wchar_t *dest;
...
dest = field_buffer(field[0], 0);
}
the compiler produces an error:
warning: assignment from incompatible pointer type [enabled by default]
dest = field_buffer(field[0], 0);
^
How to obtain from the field an array of wchar_t
?
ncursesw
uses get_wch
instead of getch
, so which function does it use instead of field_buffer()
? I couldn't find it by googling.