Is there any reliable way of getting the number of columns/rows of the current output terminal window?
I want to retrieve these numbers in a C/C++ program.
I
For Unix(-based), use ioctl(2) and TIOCGWINSZ:
#include //ioctl() and TIOCGWINSZ
#include // for STDOUT_FILENO
// ...
struct winsize size;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
/* size.ws_row is the number of rows, size.ws_col is the number of columns. */
// ...
Also, while I haven't touched Windows in the last five years, GetConsoleScreenBufferInfo() should help you get the console window size.