
Untitled
By: a guest on Sep 19th, 2010 | syntax:
C | size: 0.79 KB | hits: 60 | expires: Never
#include <sys/ioctl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc,char **argv) {
struct winsize ws;
if(argc==1) {
printf("%s [ROW/COL/X/Y]\r\nX = Count X-Pixel, Y = Count Y-Pixel\r\n", argv[0]);
exit(1);
}
if (ioctl(0,TIOCGWINSZ,&ws)!=0) {
fprintf(stderr,"TIOCGWINSZ:%s\r\n",strerror(errno));
exit(1);
}
if(!strcmp(argv[1], "ROW")){
printf("%d", ws.ws_row);
} else if(!strcmp(argv[1], "COL")){
printf("%d", ws.ws_col);
} else if(!strcmp(argv[1], "X")){
printf("%d", ws.ws_xpixel);
} else if(!strcmp(argv[1], "Y")){
printf("%d", ws.ws_ypixel);
} else {
printf("Fail.\r\n");
exit(1);
}
return 0;
}