#cpp #linux #c #console #ncurses
Данный кусок кода рисует змейку по координатам, используя функцию mvprintw. Не могу
разобраться как вывести на экран символ - ߜ. Вот код программы:
for(int i = 0; i < length; i++)
{
x = c[i].X;
y = c[i].Y;
unsigned wchar_t head;
switch(d)
{
case UP: head = 'A'; break;
case DOWN: head = L'ߜ'; break; //ߜ
// Вот этот символ ^
case LEFT: head = '<'; break;
case RIGHT: head = '>'; break;
default: break;
}
mvprintw(food.Y, food.X, "%lc", '$');
//mvprintw(i, 0, "%d %d\n",y,x);
mvprintw(y, x, "%c", (i) ? '@' : head);
}
Ответы
Ответ 1
Попробуйте, работает у вас или нет. #include#include #include int main (int ac, char *av[]) { char *loc = setlocale(LC_ALL, ""); if (av[1]) puts(loc); wchar_t wc = L'я'; wprintf(L"-- %lc --\n", wc); // wc = 'ߜ' wc = L'ߜ'; wprintf(L"-- %lc --\n", wc); // 'ߜ' } У меня avp@avp-ubu1:hashcode$ uname -a Linux avp-ubu1 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux avp@avp-ubu1:hashcode$ gcc --version gcc.real (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. avp@avp-ubu1:hashcode$ gcc twc.c && ./a.out -- я -- -- ߜ -- avp@avp-ubu1:hashcode$ ./a.out hashsj en_US.UTF-8 avp@avp-ubu1:hashcode$ Обратите внимание, что обычный вывод (puts/printf и т.п.) несовместим с выводом wide символов (wprintf и т.п.). Возможно у вас где-то тестовая печать до вывода wchar_t и поэтому ничего не отображается. Ответ 2
Обратите внимание : mvprintw(y, x, "%c", (i) ? '@' : head); Вы пытаетесь переменную типа wchar_t вывести по символу форматирования %c. В руководстве по printf написано: %c If no l modifier is present, the int argument is converted to an unsigned char, and the resulting character is written. If an l modifier is present, the wint_t (wide character) argument is converted to a multibyte sequence by a call to the wcrtomb(3) function, with a conversion state starting in the initial state, and the resulting multibyte string is written. Т.е., попробуйте использовать %lc.
Комментариев нет:
Отправить комментарий