如何打印出一个数组内的所有字符串在一个ncurses窗口?



我试图在一个ncurses窗口内显示多个随机生成的字符串数组。起初,我认为这很简单,我可以像打印任何其他数组一样打印数组:让它通过一个循环并显示它在数组中遇到的每个字符串。当我试着这样做的时候,所有的字都被打印出来了,只是它们从护士的窗户边缘出来。然后我试着想办法为每个单词设置光标的位置,但我不知道该怎么做。有谁知道一个解决方案,我可以保持字符串在窗口的边界内?如有任何帮助,不胜感激。

initscr();
string wordList[19] = {"icecream", "computer", "dictionary", "algorithm", "the", "be", "to", "of", "and", "a", "your", "you", "year", "would", "work", "with", "will", "who", "which",};
string word[19];
// parameters for window
int height, width, start_y, start_x;    
height = 9;
width = 75;
start_y = 10;
start_x = 10;
//creating the window
WINDOW *win = newwin(height, width, start_y, start_x);
refresh();
box(win, 0, 0);
wrefresh(win);

// displaying random strings from the wordList array.
srand(time(0));
for(int i=0; i<19 ; i++){
word[i] = wordList[rand() % 19];
printf("%s", word[i].c_str());
printf(" ");
}
wrefresh(win);
getch();
endwin();

不要使用printf,而是使用ncurses的功能,如waddstr()

相关内容

最新更新