getting terminal width in c
i've been looking for a way to get the terminal width from within my c program. what i keep coming up with is somthing along the lines of:

    #include <sys/ioctl.h>
    #include <stdio.h>
    
    int main (void)
    {
        struct ttysize ts;
        ioctl(0, TIOCGSIZE, &ts);
      
        printf ("lines %d\n", ts.ts_lines);
        printf ("columns %d\n", ts.ts_cols);
    }

but everytime i try that i get

    austin@:~$ gcc test.c -o test
    test.c: In function ‘main’:
    test.c:6: error: storage size of ‘ts’ isn’t known
    test.c:7: error: ‘TIOCGSIZE’ undeclared (first use in this function)
    test.c:7: error: (Each undeclared identifier is reported only once
    test.c:7: error: for each function it appears in.)

is this the best way to do this, or is there a better way? If not how can i get this to work?


getting terminal width in c
===

i've been looking for a way to get the terminal width from within my c program. what i keep coming up with is somthing along the lines of:

    #include <sys/ioctl.h>
    #include <stdio.h>
    
    int main (void)
    {
        struct ttysize ts;
        ioctl(0, TIOCGSIZE, &ts);
      
        printf ("lines %d\n", ts.ts_lines);
        printf ("columns %d\n", ts.ts_cols);
    }

but everytime i try that i get

    austin@:~$ gcc test.c -o test
    test.c: In function ‘main’:
    test.c:6: error: storage size of ‘ts’ isn’t known
    test.c:7: error: ‘TIOCGSIZE’ undeclared (first use in this function)
    test.c:7: error: (Each undeclared identifier is reported only once
    test.c:7: error: for each function it appears in.)

is this the best way to do this, or is there a better way? If not how can i get this to work?

