声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2451|回复: 6

[综合讨论] 请教大家一个关于fseek和feof的问题。

[复制链接]
发表于 2007-4-23 20:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我根据教材上的内容,写下了下面的程序。
fid=fopen('data\shujv.txt','r')
status=fseek(fid,0,'eof')
x=ftell(fid);
status1=feof(fid)
fprintf(1,'file size=%d\n',x);
根据书上的内容,status=fseek(fid,0,'eof')将把指针移到文件的结束处,而如果指针在文件结束处,由status1=feof(fid),status1将会得出1的结果,但是为什么运行后status老是0呢?
请问我运行下面的程序的时候,status的结果为什么老是0呀?
急切等待中,谢谢。
回复
分享到:

使用道具 举报

发表于 2007-4-23 20:35 | 显示全部楼层
eofstat = feof(fid) returns 1 if the end-of-file indicator for the file fid has been set and 0 otherwise. (See fopen for a complete description of fid.)

status = fseek(fid, offset, origin)
status returned value that is 0 if the fseek operation is successful and -1 if it fails. If an error occurs, use the function ferror to get more information.

建议多看看置顶贴:聚宝盆,你的问题答案就在第8个宝贝中提及到

[ 本帖最后由 ChaChing 于 2009-5-16 18:32 编辑 ]
 楼主| 发表于 2007-4-23 21:01 | 显示全部楼层
help上面说
The end-of-file indicator is set when the file position
    indicator reaches the end of the file.
那么
程序运行到
fid=fopen('data\shujv.txt','r')
status=fseek(fid,0,'eof')
x=ftell(fid);
此时
indicator for the file fid has been set
那么
feof(fid) returns 1
但是为什么每次返回值都是0呀?

不好意思,我计算机基础很差,所以希望大家能耐心的帮助我。谢谢

[ 本帖最后由 ChaChing 于 2009-7-24 22:57 编辑 ]
发表于 2009-5-16 19:03 | 显示全部楼层

回复 板凳 heaventian 的帖子

这个试了下, 不解?
发表于 2009-7-24 17:14 | 显示全部楼层
我和你的问题相同
按理说,fseek(fid,0,1)或者 fseek(fid,0,'eof')
之后 ,fid应该在文件尾,此时feof(fid)应该返回为零
但是我现在也常常得到0地返回值
二楼是否读懂了问题?聚宝盆第八个宝贝是个pdf,里面根本没有涉及这个问题
发表于 2009-7-24 23:04 | 显示全部楼层

之前曾下载过, 不过没细看过!
刚刚又找了下, 但没细心找, 好像真的没提及到! 可能老八不小心记错了吧!
或许有人知道在那一页, 再请告知!
发表于 2010-1-12 09:57 | 显示全部楼层
ftell的问题,ftell并没有将位置置于文件末尾,用fgets就可以了。。

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 02:06 , Processed in 0.066655 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表