fclose然后fopen相当于stdout? [英] fclose then fopen equivalent for stdout?

查看:103
本文介绍了fclose然后fopen相当于stdout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序写入磁带机。输出可以通过

标准输出或通过使用fopen()打开的文件输出。当所有数据都转移到磁带上时,程序需要关闭输出流,以便磁带驱动程序在磁带上写入文件标记。否则多个

保存到磁带上的数据块似乎都是

磁带上的一个大文件。


当磁带机单元设备是用fopen()

明确打开的,这是可能的:调用fclose()然后再下一批

数据fopen()磁带设备再写一些。


但是当数据通过stdout时如:


program / dev / nst0


有相同的操作吗?也许是这样的:


fputc(stdout,EOF);


或者这个


freopen(NULL," wb",stdout);





谢谢,


David Mathog

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);

or this

freopen(NULL,"wb",stdout);

?

Thanks,

David Mathog

推荐答案

David Mathog写道:
David Mathog wrote:

fputc(stdout,EOF) ;
fputc(stdout,EOF);



oops,应该是:


fputc(EOF,stdout);


David Mathog

oops, that should have been:

fputc(EOF,stdout);

David Mathog





David Mathog写道:10/25/06 12:48,:


David Mathog wrote On 10/25/06 12:48,:

我的程序写入磁带机。输出可以通过

标准输出或通过使用fopen()打开的文件输出。当所有数据都转移到磁带上时,程序需要关闭输出流,以便磁带驱动程序在磁带上写入文件标记。否则多个

保存到磁带上的数据块似乎都是

磁带上的一个大文件。


当磁带机单元设备是用fopen()

明确打开的,这是可能的:调用fclose()然后再下一批

数据fopen()磁带设备再写一些。


但是当数据通过stdout时如:


program / dev / nst0


有相同的操作吗?也许是这样的:


fputc(stdout,EOF);
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);



(在跟进中更正为fputc(EOF,stdout)。)


不,这只会写输出中的一个字符。

确切写入哪个字符的身份是

有点模糊,因为它取决于EOF的价值

宏(通常是-1,但可能是另一个负整数)

以及在本地编码中将该值转换为char

时得到的结果。 />

(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.


或者这个


freopen(NULL," wb",stdout);
or this

freopen(NULL,"wb",stdout);



未定义的行为:第一个参数应该是

是一个字符串(一个命名文件的字符串),但NULL不是

a字符串。这很像尝试fopen(NULL,wb)。


这里有一个建议:你正试图获得效果

of fclose(),对吗?是否有任何特定功能可以执行fclose()的操作?

怎么样...<<等待它> .. .fclose()?


-
Er *** ****** @ sun.com

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()?

--
Er*********@sun.com


Eric Sosman写道:
Eric Sosman wrote:

这里有一个建议:你想要获得效果

fclose(),对吗?是否有任何特定功能可以执行fclose()的操作?

怎么样...<<等待它> .. .fclose()?
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()?



我不是想要fclose,我正试图搞定


fclose()

fopen()


程序如何继续写入stdout

以便数据到达调用后的磁带设备

fclose(stdout)?


fopen()的参数与stdout重新关联具有相同的

输出关于fclose()的流?


问候,


David mathog

I''m not trying to get fclose, I''m trying to get

fclose()
fopen()

How then does the program CONTINUE to write to stdout
so that data gets to the tape device after having called
fclose(stdout)?

What parameters for fopen() reassociate stdout with the same
output stream following the fclose()?

Regards,

David mathog


这篇关于fclose然后fopen相当于stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆