W systemie Windows, należy użyć następującego kodu, aby wydrukować rozmiar okna konsoli (zapożyczoną z here):
#include <windows.h>
int main(int argc, char *argv[])
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
int columns, rows;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
printf("columns: %d\n", columns);
printf("rows: %d\n", rows);
return 0;
}
W systemie Linux, należy użyć następującego zamiast (zapożyczone z here):
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
int main (int argc, char **argv)
{
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
printf ("lines %d\n", w.ws_row);
printf ("columns %d\n", w.ws_col);
return 0; // make sure your main returns int
}
W systemie Linux, można także spróbować 'stty size' – choroba
[W] (http://stackoverflow.com/questions/18783988/how-to-get- windows-size-from-linux) może pomóc. – devnull
Możliwy duplikat [Uzyskiwanie szerokości terminala w C?] (Https://stackoverflow.com/questions/1022957/getting-termin-width-in-c) –