ncurses.h,wprintw 不起作用,即使在刷新后也是如此
ncurses.h, wprintw doesn't work, even after refresh
我正在使用库 ncurses,当我尝试调用 wprintw()
,然后在右侧 window 执行 wrefresh
时,它没有打印任何内容。
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
int main()
{
WINDOW *winTest; //The window
int rows, cols; //Rows and colums in the terminal
initscr(); //Starting NCurses
raw(); //Calling 'getch()' doesn't wait for '\n'
noecho(); //Doesn't print what's written by user
curs_set(0); //Doesn't display the cursor
getmaxyx(stdscr, rows, cols); //How many rows and colums in stdscr (the terminal)
winTest = newwin(10, 10, rows/2, cols/2); //Creates a square WINDOW at the center of the terminal
mvwprintw(winTest, 0, 0, "Test"); //Prints "Test" on the created window
wrefresh(winTest); //Refreshes so what's done is displayed
getch(); //Pause
delwin(winTest); //Free the memory for winTest
endwin(); //Ends NCurses
return 0;
}
当我执行这个时,没有任何显示。
我在 Ubuntu 14.04 LTS,我用 gcc 编译:
gcc -g -Wall -Werror -Wpedantic -Wextra -Wformat -o test.exe test.c -lncurses
然后我在 gnome-terminal 中执行。
如here所述,您应该替换:
getch();
作者:
wgetch(winTest);
I replaced the second pause, getch() with my own pause function: scanf("%*s"); and then it displayed test in the middle like it was supposed to. I think what was happening is it went through both pauses in one go so that you never saw the "Test" because it was deleted as fast as it was created. – Tony Ruth
感谢 Tony Ruth 回答了我的问题。即使我仍然不明白为什么 getch()
会删除所写的内容,但将其替换为 scanf("%*s")
就可以了!
PS:不知道如何判断这个问题已经解决了:/
编辑:您也可以在任何 window 上调用 'wgetch(aWindow)',每个 windows 都将正确显示 :)(感谢告诉它的 Ruud)
我正在使用库 ncurses,当我尝试调用 wprintw()
,然后在右侧 window 执行 wrefresh
时,它没有打印任何内容。
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
int main()
{
WINDOW *winTest; //The window
int rows, cols; //Rows and colums in the terminal
initscr(); //Starting NCurses
raw(); //Calling 'getch()' doesn't wait for '\n'
noecho(); //Doesn't print what's written by user
curs_set(0); //Doesn't display the cursor
getmaxyx(stdscr, rows, cols); //How many rows and colums in stdscr (the terminal)
winTest = newwin(10, 10, rows/2, cols/2); //Creates a square WINDOW at the center of the terminal
mvwprintw(winTest, 0, 0, "Test"); //Prints "Test" on the created window
wrefresh(winTest); //Refreshes so what's done is displayed
getch(); //Pause
delwin(winTest); //Free the memory for winTest
endwin(); //Ends NCurses
return 0;
}
当我执行这个时,没有任何显示。
我在 Ubuntu 14.04 LTS,我用 gcc 编译:
gcc -g -Wall -Werror -Wpedantic -Wextra -Wformat -o test.exe test.c -lncurses
然后我在 gnome-terminal 中执行。
如here所述,您应该替换:
getch();
作者:
wgetch(winTest);
I replaced the second pause, getch() with my own pause function: scanf("%*s"); and then it displayed test in the middle like it was supposed to. I think what was happening is it went through both pauses in one go so that you never saw the "Test" because it was deleted as fast as it was created. – Tony Ruth
感谢 Tony Ruth 回答了我的问题。即使我仍然不明白为什么 getch()
会删除所写的内容,但将其替换为 scanf("%*s")
就可以了!
PS:不知道如何判断这个问题已经解决了:/
编辑:您也可以在任何 window 上调用 'wgetch(aWindow)',每个 windows 都将正确显示 :)(感谢告诉它的 Ruud)