5

I'm trying to position a star unicode character on screen using the ncurses.h library 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]

Despite this function being well documented here together with similar functions which I can't get to work either. Is there some library I'm not including to make this work? or is there an alternative way to go about displaying this character? I appreciate any help.

Luke Collins
  • 1,433
  • 3
  • 18
  • 36
  • Possible duplicate of [Printing a Unicode Symbol in C](http://stackoverflow.com/questions/43834315/printing-a-unicode-symbol-in-c) – Thomas Dickey May 07 '17 at 19:05

1 Answers1

5

You must be compiling against the "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 make the following diff to your example code as well:

-    const wchar_t* star = L"0x2605";
+    const wchar_t* star = L"\x2605";
anthony sottile
  • 61,815
  • 15
  • 148
  • 207