I was writing a program in C++ to input values for a NxN matrix. Generally, one would enter an integer and press the Return key for NxN times. But I would like to make the cursor move the length of a tab for every value entered by the user. This carries on for a row, and then a new line is prompted for inputs for the next row. I am aware of using curses.h for such an implementation, but haven't figured out how to implement it.
Thanks.
#include <ncurses.h>
#include <iostream>
using namespace std;
int main()
{
char ch[10];
int array[4][4];
initscr();
raw();
keypad(stdscr, TRUE);
echo();
printw("Enter elements a 4x4 array: \n");
for(int i=0;i<4;i++) {
for(int j=0 ; j<4; j++) {
getstr(ch);
array[i][j]=atoi(ch);
addch('\t'); // This is executed after the newline return is received
refresh();
}
addch('\n');
}
getch();
endwin();
return 0;
}
The question is lacking code : what have you tried ? What is the problem ?
If you want to get into ncurses and don't know where to start, I'd recommend reading some tutorials : see this page and this page regarding keyboard interfacing. Feel free to come and ask more questions if you encounter issues once you have some code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With