Here is the code I am using 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 winsize
reference.
But the code prints only zeros. If I use ws_col
or ws_row
it works fine.
Please help, thanks !