Re: fclose then fopen equivalent for stdout?
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Wed, 25 Oct 2006 13:20:58 -0400
David Mathog wrote On 10/25/06 12:48,:
A program of mine writes to a tape unit. Output can be either through
stdout or through a file opened with fopen(). When all the data is
transferred to tape the program needs to close the output stream so that
the tape driver will write a filemark on the tape. Otherwise multiple
clumps of data saved to tape would all appear to be one big file on the
tape.
When the tape unit device was explicitly opened with fopen()
that's possible: call fclose() and then for the next batch
of data fopen() the tape device again and write some more.
However when data is going through stdout like:
program > /dev/nst0
is there an equivalent operation? Maybe something like this:
fputc(stdout,EOF);
(Corrected to fputc(EOF, stdout) in a follow-up.)
No, this would merely write a character to the output.
The identity of exactly which character gets written is a
little fuzzy in that it depends on the value of the EOF
macro (usually -1, but could be another negative integer)
and on what you get when converting that value to a char
in the local encoding.
or this
freopen(NULL,"wb",stdout);
Undefined behavior: The first argument is supposed to
be a string (a string that names a file), but NULL is not
a string. It's much like trying fopen(NULL, "wb").
Here's a suggestion: You're trying to obtain the effect
of fclose(), right? Does any particular function spring to
mind as being likely to perform the operations of fclose()?
How about ... <<wait for it>> ... fclose()?
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: fclose then fopen equivalent for stdout?
- From: Harald van Dijk
- Re: fclose then fopen equivalent for stdout?
- From: David Mathog
- Re: fclose then fopen equivalent for stdout?
- References:
- fclose then fopen equivalent for stdout?
- From: David Mathog
- fclose then fopen equivalent for stdout?
- Prev by Date: Re: Another Mersenne Twister question
- Next by Date: Re: bit position
- Previous by thread: Re: fclose then fopen equivalent for stdout?
- Next by thread: Re: fclose then fopen equivalent for stdout?
- Index(es):
Relevant Pages
|
|