Getting terminal size in c for windows?

后端 未结 3 1090
野趣味
野趣味 2020-11-28 08:45

How to check ymax and xmax in a console window, under Windows, using plain c?

There is this piece of code for linux:

         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 09:33

    (Partial answer)

    This code:

    CONSOLE_SCREEN_BUFFER_INFO csbi;
    int ret;
    ret = GetConsoleScreenBufferInfo(GetStdHandle( STD_OUTPUT_HANDLE ),&csbi);
    if(ret)
    {
        printf("Console Buffer Width: %d\n", csbi.dwSize.X);
        printf("Console Buffer Height: %d\n", csbi.dwSize.Y);
    }
    

    Gives the size of the buffer. The only problem is that dwSize.Y is not really the size of the screen (300 here instead of 25 lines). But dwSize.X matches the column's number. Needs only windows.h to work.

提交回复
热议问题