Replace return using tab for standard input

I wrote a C ++ program to input values ​​for an NxN matrix. Typically, you can enter an integer and press the Return key for NxN times. But I would like the cursor to move the tab length for each value entered by the user. This is done for the line, and then a new line is displayed for input for the next line. I know the use of curses.h for such an implementation, but have not figured out how to implement it.

Thank.

#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;
}
+3
source share
3 answers

The question is missing code: what have you tried? What is the problem?

ncurses , , : . this page . , , .

+3

cin >> value;, . ( , , ).

0

, - ?

( ).

If the user has decided to press enter after each element, after each element must be entered. If he simply divides the objects into a space, he should not display anything else.

0
source

Source: https://habr.com/ru/post/1776196/


All Articles