使用fseek()确定EOF? [英] Determining EOF using fseek()?

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

问题描述

嘿,


我想知道是否有可能确定你是否使用

fseek命中''EOF'?我正在使用fseek从头到尾遍历文件

并将数据捕获到链表结构中。但是,我的循环

看起来效果不好 - 它实际上完全摸不着:


while((a = fseek(fp,0, SEEK_CUR))== 0){

//这里的代码

}


对我来说,不要破坏它是非常重要的

游标的当前位置,因为我依赖它来从文本文件中获取数据。我认为
认为循环可以正常工作,因为fseek只会在错误上返回一个

非零整数,但不幸的是情况并非如此。

任何有使用fseek()或其他功能的建议吗?


任何帮助将不胜感激!谢谢。

Hey,

I was wondering if it was possible to determine if you hit ''EOF'' using
fseek? I''m using fseek to traverse through the file from start to end
and capturing the data into a linked list structure. However, my loop
doesn''t seem to work well - it totally fumbles out actually:

while ((a = fseek(fp,0,SEEK_CUR)) == 0){
// code here
}

Its quite important for me not to disrupt the current position of the
cursor since I rely on that to fetch the data from the text file. I
thought that the loop would work fine since fseek only returns a
non-zero integer on an error but unfortunately this is not the case.
Anyone with suggestions with using fseek() or some other function?

Any help would be greatly appreciated! Thanks.

推荐答案

2004年8月27日星期五14:08:23 GMT,

Orion< wo ** **@bigpond.net.au>写道:

On Fri, 27 Aug 2004 14:08:23 GMT,
Orion <wo****@bigpond.net.au> wrote:

嘿,

我想知道是否有可能确定你是否使用
点击''EOF'' FSEEK?我正在使用fseek从头到尾遍历文件并将数据捕获到链表结构中。然而,我的循环似乎并没有奏效 - 它实际上完全摸索:

while((a = fseek(fp,0,SEEK_CUR))== 0){
//代码在这里
}
Hey,

I was wondering if it was possible to determine if you hit ''EOF'' using
fseek? I''m using fseek to traverse through the file from start to end
and capturing the data into a linked list structure. However, my loop
doesn''t seem to work well - it totally fumbles out actually:

while ((a = fseek(fp,0,SEEK_CUR)) == 0){
// code here
}




我不认为只要fp是有效的,它就会返回错误/>
表示可搜索文件的FILE指针。确定

eof的正常方法是从文件中读取并查看它是否返回eof指示。


Villy



I wouldn''t expect this would ever return an error as long as fp is a valid
FILE pointer representing a seekable file. The normal way to determine
eof is to read from the file and see if it returns an eof indication.

Villy


Orion写道:
嘿,

我想知道是否有可能确定你是否使用
点击''EOF'' FSEEK?我正在使用fseek从头到尾遍历文件并将数据捕获到链表结构中。 [...]
Hey,

I was wondering if it was possible to determine if you hit ''EOF'' using
fseek? I''m using fseek to traverse through the file from start to end
and capturing the data into a linked list structure. [...]




如果您正在从头到尾阅读整个文件,为什么

你在使用fseek()吗?只需继续调用fgets()或

fread()或者你正在使用的任何东西来吸收数据,当

你得到文件结尾时函数会告诉你如此[*]由

返回值EOF。

[*] EOF返回值也可以表示实际的I / O

错误而不是文件结束。对于腰带和吊带

确定性,您可以使用feof()或ferror()来计算出EOF值实际意味着什么。


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



If you''re reading the whole file "from start to end," why
are you using fseek() at all? Just keep calling fgets() or
fread() or whatever you''re using to soak up the data, and when
you get to end-of-file the function will tell you so[*] by
returning the value EOF.
[*] The EOF return value can also indicate an actual I/O
error rather than end-of-file. For belt-and-suspenders
certainty, you can use feof() or ferror() to figure out
what the EOF value actually meant.

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


Orion写道:
Orion wrote:
嘿,

我在想如果有可能确定你是否使用
fseek命中''EOF'?我正在使用fseek从头到尾遍历文件并将数据捕获到链表结构中。然而,我的循环似乎并没有奏效 - 它实际上完全摸索:

while((a = fseek(fp,0,SEEK_CUR))== 0){
//代码在这里


对我来说非常重要的是不要破坏
游标的当前位置,因为我依靠它来从中获取数据文本文件。我认为循环可以正常工作,因为fseek只会在错误上返回一个非零整数,但遗憾的是情况并非如此。
任何有使用fseek()或某些建议的人其他功能?

任何帮助将不胜感激!谢谢。
Hey,

I was wondering if it was possible to determine if you hit ''EOF'' using
fseek? I''m using fseek to traverse through the file from start to end
and capturing the data into a linked list structure. However, my loop
doesn''t seem to work well - it totally fumbles out actually:

while ((a = fseek(fp,0,SEEK_CUR)) == 0){
// code here
}

Its quite important for me not to disrupt the current position of the
cursor since I rely on that to fetch the data from the text file. I
thought that the loop would work fine since fseek only returns a
non-zero integer on an error but unfortunately this is not the case.
Anyone with suggestions with using fseek() or some other function?

Any help would be greatly appreciated! Thanks.




当然,有这些用途的feof(fp)。


-

Karthik。



Of course, there is feof(fp) for these purposes.

--
Karthik.


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

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