以下のコードで取得することができる。
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
int main(int argc, char *argv[]) {
struct winsize ws;
if( ioctl( STDOUT_FILENO, TIOCGWINSZ, &ws ) != -1 ) {
printf("Width = %d\n", ws.ws_col);
printf("Height = %d\n", ws.ws_row);
}
return 0;
}
実行結果
% ./a.out
Width = 86
Height = 27
0件のコメント