Printing wide unicode character with ncurses

I am trying to position an asterisk star symbol on the screen using a library ncurses.h

in C on Ubuntu. The code I'm trying to run is the following:

#include <stdio.h>
#include <wchar.h>
#include <curses.h>
#include <ncurses.h>
#include <stdlib.h>
#include <wctype.h>
#include <locale.h>

int main() {
    setlocale(LC_CTYPE, "");

    initscr();
    cbreak();

    WINDOW *win = newwin(0, 0, 0, 0);
    refresh();
    wrefresh(win);

    const wchar_t* star = L"0x2605";
    mvaddwstr(3, 3, star);

    getch();
    endwin();
}

      

But I keep getting the error

implicit declaration of function β€˜mvaddwstr’ [-Wimplicit-function-declaration]

      

Even though this feature is well documented here along with similar features I can't get it either. Is there some library I am not including to make this work? or is there an alternative way to show this symbol? I appreciate any help.

+3


source to share


1 answer


You should compile against "narrow" curses (ncurses vs ncursesw)

I was able to compile your example on ubuntu 16.04 with the following:

apt install libncursesw5-dev

# --cflags expanded to: -D_GNU_SOURCE -I/usr/include/ncursesw
gcc main.c $(ncursesw5-config --cflags) -c
# --libs expanded to: -lncursesw -ltinfo
gcc main.o $(ncursesw5-config --libs) -o main

      

And then



./main

      

I had to do the following code and in your example code:

-    const wchar_t* star = L"0x2605";
+    const wchar_t* star = L"\x2605";

      

+2


source







All Articles