I'm trying to display an array of multiple random generated strings within a ncurses window. At first, I thought this was going to be simple and I can print the array as I would with any other array: putting it through a loop and displaying each string that it comes across within the array. When I tried this, all the words were printing, just that they were coming out of the borders of the ncurses window. Then I tried to figure out a way I can set the location of the cursor for each word, but I can't figure out how I would do that. Does anybody know a solution I can keep the strings within the borders of the window? Any help would be appreciated.
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();
CodePudding user response:
Don't use printf
, use ncurses' functions like waddstr()
instead.