Guest

Untitled

By: a guest on Sep 19th, 2010  |  syntax: C  |  size: 0.79 KB  |  hits: 60  |  expires: Never
download  |  raw  |  embed  |  report abuse
This paste has a previous version, view the difference. Copied
  1. #include <sys/ioctl.h>
  2. #include <string.h>
  3. #include <errno.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6.  
  7. int main(int argc,char **argv) {
  8.     struct winsize ws;
  9.     if(argc==1) {
  10.         printf("%s [ROW/COL/X/Y]\r\nX = Count X-Pixel, Y = Count Y-Pixel\r\n", argv[0]);
  11.         exit(1);
  12.     }
  13.     if (ioctl(0,TIOCGWINSZ,&ws)!=0) {
  14.         fprintf(stderr,"TIOCGWINSZ:%s\r\n",strerror(errno));
  15.         exit(1);
  16.     }
  17.     if(!strcmp(argv[1], "ROW")){
  18.         printf("%d", ws.ws_row);
  19.     } else if(!strcmp(argv[1], "COL")){
  20.         printf("%d", ws.ws_col);
  21.     } else if(!strcmp(argv[1], "X")){
  22.         printf("%d", ws.ws_xpixel);
  23.     } else if(!strcmp(argv[1], "Y")){
  24.         printf("%d", ws.ws_ypixel);
  25.     } else {
  26.         printf("Fail.\r\n");
  27.         exit(1);
  28.     }
  29.     return 0;
  30. }