Some how the open(file,flag, acc) returns 0 and write to the screen, instead of the file ???

I am out of idea what to do to resolve the problem!

I need to use the open(file, for.., access) function to write a file.

Never have the situation like that: it is return 0 - zero.
As a result all write(..) going to the screen!

What the problem it could be?

I do not even know what to show in code.
Opened this way:

      if (fdRPT  = open( rpt_fl,  O_WRONLY|O_CREAT|O_TRUNC, 0666) == -1 )
      {  .../*error*/  ;}        

The 'rpt_fl' is fine

...
       printf ("\n -- The report file is: >%s< -- \n",rpt_fl);
....

prints out:

 -- The report file is: >DATA/elm0653M.rpt.0008< --

and

> ll DATA/elm0653M.rpt.0008
-rw-rw-rw-   1 dca0701  dstnse         0 Mar  8 13:06 DATA/elm0653M.rpt.0008

I undestand that the system by default should have the '0' descriptor associated with the standart output and have it unavailable (or already assighned) on any, even first a file descriptor request (by the open(..),) but it is not happening in my case.
I am stucked with how get it resolve.

What could be the reason for such behavior?
What would you advise to do to realise the problem or correct it?

I am appreciate any help and every try!

Pretty sure the value's being overwritten somewhere. Even if it did return 0, it wouldn't be writing to the screen when fd 0 was freshly opened.

Try:

      if ((fdRPT  = open( rpt_fl,  O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1 )
      {  .../*error*/  ;}

I think the result of the == is being assigned to fdRPT.

It appsolutely right!!!
Thank you very much!!!

Now it works as expected!
:o:o