How to get terminal window width?

后端 未结 3 732
猫巷女王i
猫巷女王i 2020-12-11 23:10

I am working on embedded system using C and linux. User can connect to the device via SSH or a console serial cable. He can do this through PuTTY o

3条回答
  •  萌比男神i
    2020-12-11 23:36

    I use this code to print a bunch of equals signs as a divider. Works on most boxes/terms I've tried. Not sure what devices you are talking about. Worth a try I guess ;-)

    #include 
    #include 
    #include 
    int main(int argc, char *argv[])
    {
       struct winsize ws;
       ioctl(0, TIOCGWINSZ, &ws);
    
       int i=0;
       for(;i<10*ws.ws_col;++i) printf("=");
       printf("\n");
       return 0;
    }
    

提交回复
热议问题