Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Strange thing with a C program

Daniel Clar
Advisor

Strange thing with a C program

Here is the following program :

#include
int main()
{
fputs(" dcc: C programs checker. Copyright 1995 Supelec.\n", stdout);
fputs("1 warning(s) reported (0 message(s) masked).", stderr);
(void) getchar();
fputs("----------------------------------------\n", stdout);
fputs("Stderr2\n", stderr);
fputs("Stderr21\n", stderr);
return 1;
}

If you run it on a Unix system, it's OK.

If you run it on an OpenVMs system there is a problem because Stderr2 is written on the same line as the dashes so there is no return to the line after the first fputs.

if you comment the getchar, it's working....

Is it a bug or an hidden feature ?

Thanks

Daniel
Daniel
3 REPLIES
Martin P.J. Zinser
Honored Contributor

Re: Strange thing with a C program

Hello Daniel,

the problem is the missing \n at teh end of the

fputs("1 warning(s) reported (0 message(s) masked).", stderr);

line. So stderr tries to continue to write on the same line as before, which has already been used
by stdout.

Add the \n and your output should look ok.

Greetings, Martin
Daniel Clar
Advisor

Re: Strange thing with a C program

Martin,

I agree that it could be fixed this way, but why does it work on a Unix system ?

Thanks


Daniel
Daniel
Martin P.J. Zinser
Honored Contributor

Re: Strange thing with a C program

Hello Daniel,

I am not entirely sure about this either. It is
obviously an interaction between the various I/O streams on the terminal device. Each single stream behaves exactly as you would expect. To see this do the following:

$define/user sys$output out.txt
$define/user sys$error err.txt

then run your test program. Afterwards out.txt and err.txt do contain exactly what you would expect from the fputs statements, i.e. without the \n err.txt is

1 warning(s) reported (0 message(s) masked).Stderr2
Stderr21


Greetings, Martin