Skip to content

Instantly share code, notes, and snippets.

@sbz
Created April 14, 2017 02:05
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbz/4ba35bdaf51629216dbce84636a4cccf to your computer and use it in GitHub Desktop.
Save sbz/4ba35bdaf51629216dbce84636a4cccf to your computer and use it in GitHub Desktop.
get terminal size using ioctl get win size (TIOCGWINSZ) in C
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
int
main(void) {
struct winsize ws;
ioctl(STDIN_FILENO, TIOCGWINSZ, &ws);
printf ("lines %d\n", ws.ws_row);
printf ("columns %d\n", ws.ws_col);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment