title: Getting terminal size in c for windows?
body: <p>How to check ymax and xmax in a console window, under Windows, using plain c?</p>
  
  <p>There is this piece of code for linux:</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;sys/ioctl.h&gt;
  int main (void)
  {
      struct winsize max;
      ioctl(0, TIOCGWINSZ , &amp;max);
      printf ("lines %d\n", max.ws_row);
      printf ("columns %d\n", max.ws_col);
  }
  </code></pre>
  
  <p>Now I wonder how can I do the same for windows. I tried <code>winioctl.h</code> but it does not define <code>struct winsize</code> nor any other with a similar name.</p>
  
  <p>Any tips? Thanks.</p>
  
  <p>PS. In linux you also can find the console size using <code>getenv("LINES");</code>. Is there a similar variable under windows?</p>
  
  <p>PPS. Also, there is always <code>ncurses.h</code>, that I suppose work both systems, but I'm avoiding it because of conflicts with other libraries I have.</p>
  
  <p>PPPS. This question here <a href="https://stackoverflow.com/questions/1022957/getting-terminal-width-in-c">Getting terminal width in C?</a> has a lot of tips, so no need to repeat that.</p>