Print a wide unicode character with ncurses

放肆的年华 提交于 2019-12-13 13:14:22

问题


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.


回答1:


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";


来源:https://stackoverflow.com/questions/43834833/print-a-wide-unicode-character-with-ncurses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!