title: How to get the cursor position in a C program using termcap, without writing a character?
body: <p>I would like to know how to get the cursor position (x, y) in my program, without writing anything on the screen neither tracking it all the time.</p>
  <p>I found out a way to get its position with this function (I don't check the return of read, write, etc here to write a smaller code on this subject but I do it in my program):</p>
  <pre><code>void get_cursor_position(int *col, int *rows)
  {
      int a = 0;
      int i = 0;
      char buf[4];
  
      write(1, &quot;\033[6n&quot;, 4); // string asking for the cursor position
      read(1, buf, 4);
  
      while (buf[i])
      {
          if (buf[i] &gt;= 48 &amp;&amp; buf[i] &lt;= 57)
          {
              if (a == 0)
                  *rows = atoi(&amp;buf[i]) - 1;
              else
                  *col = atoi(&amp;buf[i]) - 1;
              a++;
          }
          i++;
      }
  }
  </code></pre>
  <p>This function gives me the exact cursor position (*rows = y, *col = x), but it writes on the screen.</p>
  <p>How can I get the cursor position without writing anything on the screen?<br />
  (If the cursor is on one of the printed characters, it will overwrite it.)<br />
  Should echo be toggled before and after sending the escape sequence?</p>
  <p>This is a school project, so I only can use termcap, I can't use ncurses functions, the only allowed functions are tputs, tgoto, tgetstr, tgetnum, tgetflag.</p>