Liemani

blog

홈으로

unix_lecture_notes

October 03, 2021

40p

#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>

void    a005()
{
    int             tty;
    struct winsize  window_structure;

    tty = open("/dev/tty", O_RDONLY);
    ioctl(tty, TIOCGWINSZ, &window_structure);
	printf("row: %d, col: %d \n", window_structure.ws_row, window_structure.ws_col);
}
struct winsize {
    unsigned short  ws_row;
    unsigned short  ws_col;
    unsigned short  ws_xpixel;
    unsigned short  ws_ypixel;
};

compile 하여 생성된 실행 파일을 직접 수정하여 출력 결과를 변경해보기

#include <stdio.h>

int main()
{
    printf("Hello, World! \n");
    return (0);
}
% ./a.out
world. hello?
%