c++ - Where should refresh() be using ncurses? -
my code below outputs nothing when starts. prints following when type 1,2,3:
1enter value of argv[1]:49 2enter value of argv[2]:50 3enter value of argv[3]:51
i quite confused refresh() should placed when using loop. trying achieve comments inside loop.
int main() { initscr(); int argv[3]; int argvlen = sizeof(argv)/sizeof(*argv); (int i=0; i<argvlen; i++) { int n = getch(); printw("enter value of argv[%d]: %d \n", i+1, n); argv[i] = n; refresh(); //cout << "enter value of argv[" << i+1 << "]:" << endl; //cin >> argv[i]; } endwin(); return 0; }
getch()
returns char, such '1'
, '2'
or '3'
. integer values of these 49, 50, 51. if need integer value, should subtract '0'
.
int n = getch() - '0';
beware works digits (0 9). if enter else won't give expected answer, want add additional checks there.
Comments
Post a Comment