Here is the code that I use to print the resolution in pixels of the current terminal.
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[]) {
struct winsize ww;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &ww);
printf ("x-pixels %d\n", ww.ws_xpixel);
printf ("y-pixels %d\n", ww.ws_ypixel);
return 0;
}
I used this as a link winsize. But the code only prints zeros. If I use ws_color ws_row, it works fine.
Please help, thanks!
source
share