如何将'EOF'转换为FILE流。 [英] How to fputc 'EOF' to a FILE stream.

查看:49
本文介绍了如何将'EOF'转换为FILE流。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨天才,


我有一种情况,我应该继续阅读文件流,直到

一个位置。而且我必须立即写下EOF字符,以便

清除文件的其余部分。


有什么想法吗?....


在此先感谢

Suresh

Hi talents,

I have a situation where , I should keep on reading a FILE stream until
a location. And I have to immediately write the EOF character , so that
the rest of the file is cleared.

Any idea?....

Thanks in Advance
Suresh

推荐答案

ok ****** @ gmail.com 写道:
ok******@gmail.com writes:
我的情况是,我应继续阅读文件流,直到
一个位置。我必须立即写下EOF字符,以便清除文件的其余部分。
I have a situation where , I should keep on reading a FILE stream until
a location. And I have to immediately write the EOF character , so that
the rest of the file is cleared.




这是一个FAQ。


19.13:如何在不完全清除

或重写文件的情况下将文件缩短到原位?


答:BSD系统提供ftruncate(),其他几个提供chsize(),

和一些可能提供(可能未记录的)fcntl选项

F_FREESP。在MS-DOS下,你有时可以使用write(fd,"",0)。

但是,没有便携式解决方案,也没有办法删除

开头就是块。另见问题19.14。

-

int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz。\

\\ \\ n,* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\

); while(* q){ i + = strchr(p,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i] \

);} return 0;}



This is a FAQ.

19.13: How can a file be shortened in-place without completely clearing
or rewriting it?

A: BSD systems provide ftruncate(), several others supply chsize(),
and a few may provide a (possibly undocumented) fcntl option
F_FREESP. Under MS-DOS, you can sometimes use write(fd, "", 0).
However, there is no portable solution, nor a way to delete
blocks at the beginning. See also question 19.14.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}


ok******@gmail.com 写道:
我有一种情况,我应该继续阅读文件流,直到
一个位置。我必须立即写下EOF字符,以便清除文件的其余部分。
I have a situation where , I should keep on reading a FILE stream until
a location. And I have to immediately write the EOF character , so that
the rest of the file is cleared.




EOF不是一个字符。 EOF是一个宏,它扩展为负的

常量,用于表示文件结束条件。 (那个

条件可能会被某些系统上的某些字符表示,但

表示系统特定的,与EOF无关。)


见Ben Pfaff的答案。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< * GT; < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



EOF is not a character. EOF is a macro that expands to a negative
constant that''s used to indicate an end-of-file condition. (That
condition might be indicated by some character on some systems, but
that''s system-specific, and is not related to EOF.)

See Ben Pfaff''s answer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


ok ****** @ gmail.com 写道:

我有一种情况,我应该继续阅读文件流
直到某个位置。我必须立即写EOF字符,
以便清除文件的其余部分。

I have a situation where , I should keep on reading a FILE stream
until a location. And I have to immediately write the EOF character,
so that the rest of the file is cleared.




没有EOF字符。

流只有一个EOF条件。处理您的要求的唯一便携方式是

复制文件,直到您到达停止点。然后关闭

文件和新副本。


EOF是负的int值,而不是char值。它与

所有字符不同。你不知道它是什么,但你知道它是stdio.h中定义的
。 Streams返回该值以表示他们已经遇到文件结束条件,即没有更多

数据。


-

"如果你想通过groups.google.com发布一个后续内容,请不要使用

破损的回复链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。 - Keith Thompson

更多详细信息:< http://cfaj.freeshell.org/google/>

另见< http://www.safalra .com / special / googlegroupsreply />



There is no EOF character. There is only an EOF condition of a
stream. The only portable way to handle your requirement is to
copy the file until you reach the stopping point. Then close both
the file and the new copy.

EOF is a negative int value, not a char value. It is distinct from
all characters. You don''t know what it is, but you do know it is
defined in stdio.h. Streams return that value to signal that they
have encountered the end-of-file condition, i.e. there is no more
data.

--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>


这篇关于如何将'EOF'转换为FILE流。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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