Get terminal size via IOCTL
#include <sys/ioctl.h> #include <stdio.h> #include <unistd.h> int main(void) { struct winsize ws; ioctl(STDIN_FILENO, TIOCGWINSZ, &ws); // ws.ws_row => nrows // ws.ws_col => ncols }