Advertisement

03.14.2008 at 09:11PM PDT, ID: 23243646
[x]
Attachment Details

Small test function, please run on multiple systems, is it portable?  Terminal $COLUMNS

Asked by brycen in Open Source Programming, Operating Systems Miscellaneous, Miscellaneous

Tags: C

I'm building a grid of OS support for telling an application what the terminal width is.  Could you run this small test C program, and report results on various platforms?  Is there a universal way to write a C program, to correctly get the terminal width, that will work across all environments that have consoles (e.g. Windows, cygwin, unix, linux, os x, BeOS, etc.)?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
/*
**  Terminal size parameters test program.
**      cc -l readline -o col_test col_test.c
**      Run this, resize window, run again.
**
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>
 
 
main()
{
        struct winsize win;
        int temp;
 
        printf("$COLUMNS=%s\n",getenv("COLUMNS"));
        if( temp = ioctl(STDOUT_FILENO, TIOCGWINSZ, (void *)&win) ) {
            printf("TIOCGWINSZ failed %d\n",temp);
        } else {
            printf("TIOCGWINSZ win.ws_col=%d\n",win.ws_col);
        }
 
        readline("What OS are you running this on? ");
        readline("What OS are you typing on? ");
        readline("What terminal emulator are you using? ");
 
        printf("$COLUMNS=%s\n",getenv("COLUMNS"));
        if( temp = ioctl(STDOUT_FILENO, TIOCGWINSZ, (void *)&win) ) {
            printf("TIOCGWINSZ failed %d\n",temp);
        } else {
            printf("TIOCGWINSZ win.ws_col=%d\n",win.ws_col);
        }
}
 
Keywords: Small test function, please run on mult…
 
Loading Advertisement...
 
[+][-]03.14.2008 at 09:13PM PDT, ID: 21131425

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2008 at 09:14PM PDT, ID: 21131428

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.14.2008 at 09:18PM PDT, ID: 21131432

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.16.2008 at 10:01AM PDT, ID: 21137511

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.16.2008 at 10:13AM PDT, ID: 21137558

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.16.2008 at 10:15AM PDT, ID: 21137567

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.16.2008 at 10:18AM PDT, ID: 21137583

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.16.2008 at 10:39AM PDT, ID: 21137673

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.16.2008 at 10:43AM PDT, ID: 21137687

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.18.2008 at 01:02AM PDT, ID: 21149044

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Open Source Programming, Operating Systems Miscellaneous, Miscellaneous
Tags: C
Sign Up Now!
Solution Provided By: JustUNIX
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03.26.2008 at 09:12PM PDT, ID: 21218508

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.27.2008 at 01:45AM PDT, ID: 21219480

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.29.2008 at 05:08PM PDT, ID: 21238763

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.30.2008 at 02:25AM PDT, ID: 21240099

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628