feof(),fseek(),fread() [英] feof(), fseek(), fread()

查看:104
本文介绍了feof(),fseek(),fread()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果fseek()总是清除EOF,有没有办法让我从文件的

偏移量fread()并仍然能够检测到EOF?没有使用

fseek()。我还需要频繁地寻找文件中的偏移量(向前和向后)并从该偏移量中进行fread()。


或者更好的是,谁能让我知道一些好的方法来实现上面我需要做的事情?我可以抓住文件并且能够在不使用fread的情况下读取
()?使用内存地址?

谢谢

解决方案

" ericunfuk" < xu *********** @ gmail.comwrites:


如果fseek()总是清除EOF,有没有办法让我去fread()来自一个文件的

偏移并且仍能检测到EOF?即没有使用

fseek()。我还需要经常寻找文件

中的偏移量(向前和向后)并从该偏移量中进行fread()。



请解释以前几个类似问题之前几个问题的答案如何不充分。

-

给我们所有人的教训:即使在琐事中也有陷阱。

--Eric Sosman


< blockquote> 3月24日,01:40,Ben Pfaff< b ... @ cs.stanford.eduwrote:


" ericunfuk" < xuwenduan2 ... @ gmail.comwrites:


如果fseek()总是清除EOF,有没有办法让我从

文件的偏移量仍然可以检测到EOF?即没有使用

fseek()。我还需要经常寻找文件

中的偏移量(向前和向后)并从该偏移量中进行fread()。



请解释以前几个类似问题之前几个问题的答案如何不充分。

-

给我们所有人的教训:即使在琐事中也有陷阱。

--Eric Sosman



我仍​​然不知道我怎么能在我总是使用fseek时检测到EOF()

(它总是清除EOF),我必须能够向前寻找

在文件中倒退,但我现在还不知道怎么办

这个没有fseek(),这就是我发布这个问题的原因。


" ericunfuk" < xu *********** @ gmail.comwrites:


3月24日,01:40,Ben Pfaff< b .. 。@ cs.stanford.eduwrote:


>" ericunfuk" < xuwenduan2 ... @ gmail.comwrites:


如果fseek()总是清除EOF,有没有办法让我从

文件的偏移量仍然可以检测到EOF?即没有使用

fseek()。我还需要经常寻找文件

中的偏移量(向前和向后)并从该偏移量中进行fread()。


请解释以前几个以前类似问题的几个答案如何不充分。



我仍​​然不知道如何在我总是使用fseek时检测到EOF()

(它总是清除EOF),我必须能够在文件中向前搜索并向后搜索
,但到目前为止我仍然不知道怎么办

这个没有fseek(),这就是我发布这个问题的原因。



在fseek()之后,调用fread()来读取数据。如果它返回一个简短的

读取,则表示您遇到错误或文件结束。使用

ferror()和feof()来区分错误和文件结尾。


这就是我上次说的。怎么不合适呢?

-

Ben Pfaff
bl * @ cs .stanford.edu
http://benpfaff.org


If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?i.e. withouting using
fseek(). I also need to seek to an offset in the file
frequently(forwards and backwards) and do fread() from that offset.

Or better still, could anyone let me know some good ways to achieve
what I need to do as above?Can I get hold of the file and being able
to read in without using fread()? Using memory addresses?
Thanks

解决方案

"ericunfuk" <xu***********@gmail.comwrites:

If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?i.e. withouting using
fseek(). I also need to seek to an offset in the file
frequently(forwards and backwards) and do fread() from that offset.

Please explain how the several previous answers to your several
previous similar questions are inadequate.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman


On 24 Mar, 01:40, Ben Pfaff <b...@cs.stanford.eduwrote:

"ericunfuk" <xuwenduan2...@gmail.comwrites:

If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?i.e. withouting using
fseek(). I also need to seek to an offset in the file
frequently(forwards and backwards) and do fread() from that offset.


Please explain how the several previous answers to your several
previous similar questions are inadequate.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman

I still don''t know how can I detect EOF while I''m always use fseek()
(It always clears EOF), and I must be able to seek forwards and
backwards in the file, but I still don''t know up to now how can I do
this without fseek(), that''s why I posted this question.


"ericunfuk" <xu***********@gmail.comwrites:

On 24 Mar, 01:40, Ben Pfaff <b...@cs.stanford.eduwrote:

>"ericunfuk" <xuwenduan2...@gmail.comwrites:

If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?i.e. withouting using
fseek(). I also need to seek to an offset in the file
frequently(forwards and backwards) and do fread() from that offset.


Please explain how the several previous answers to your several
previous similar questions are inadequate.


I still don''t know how can I detect EOF while I''m always use fseek()
(It always clears EOF), and I must be able to seek forwards and
backwards in the file, but I still don''t know up to now how can I do
this without fseek(), that''s why I posted this question.

After fseek(), call fread() to read data. If it returns a short
read, you have either encountered an error or end of file. Use
ferror() and feof() to distinguish an error from end of file.

This is what I said last time. How is it inadequate?
--
Ben Pfaff
bl*@cs.stanford.edu
http://benpfaff.org


这篇关于feof(),fseek(),fread()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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