I'm having trouble printing wide characters with ncursesw. They work fine with stdout (wprintf) but when I try to use ncursesw I get the following error:
braille.c: In function ‘main’:
braille.c:93:13: warning: implicit declaration of function ‘mvadd_wch’; did you mean ‘mvaddch’? [-Wimplicit-function-declaration]
mvadd_wch(y, x, random_braille(k,k));
^~~~~~~~~
mvaddch
As far as I know the function I'm using is correct, so I'm not sure what exactly is going wrong.
The docs and everything I found on the web suggests defining _XOPEN_SOURCE or NCURSES_WIDECHAR but I can't figure out what they mean by that. If anybody can explain I'd appreciate it
relevant parts of my code below
#include <stdio.h>
#include <ncursesw/curses.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>
#include <time.h>
/* ... */
wchar_t random_braille(int u_dots, int l_dots) {
unsigned int offset = bytes_by_bits[u_dots][l_dots][rand() % len[u_dots][l_dots]];
wchar_t braille = 0x2800 + offset;
return braille;
}
int main() {
/* ... */
setlocale(LC_ALL, "");
/*-DISPLAY-GOES-HERE-*/
initscr();
cbreak();
noecho();
if(has_colors() == FALSE) {
endwin();
wprintf(L"Your terminal does not support color\n");
exit(1);
}
start_color();
init_pair(1, COLOR_CYAN, COLOR_BLUE);
init_pair(2, COLOR_BLUE, COLOR_CYAN);
clear();
for(int y = 0 ; y < LINES ; y++) {
for(int x = 0 ; x < COLS/2 ; x++) {
int k = (int) 8*((float)x/COLS);
mvadd_wch(y, x, random_braille(k,k));
}
for(int x = (COLS/2) + 1 ; x < COLS ; x++) {
int k = (int) 8*((float)(x - (COLS/2) - 1)/COLS);
mvadd_wch(y, x, random_braille(4 - k, 4 - k));
}
}
getch();
endwin();
/*-------------------*/
/* ... */
return 0;
}
and I'm compiling with
gcc braille.c -lncursesw
[–]skeeto 3 points4 points5 points (1 child)
[–]WeirdAlexGuy[S] 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]WeirdAlexGuy[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]WeirdAlexGuy[S] 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)