回 帖 发 新 帖 刷新版面

主题:[讨论]搞文件时遇到的怪现象

while(feof(fp)!=1)和while(!feof(fp))从逻辑上不是一样大吗[em10]


怎么实际用起来不一样啊????

回复列表 (共11个回复)

沙发

while(feof(fp)!=1)和while(!feof(fp))

读取到文件尾部是返回-1 
只要feof不是0 !feof的值 =0
想想吧

板凳


那这两个while(feof(fp)!=1)和while(!feof(fp))

我觉得它们一样啊  怎么用作条件是怎么不一样???


feof遇到文件结束是返回1吧[em14]

3 楼

[quote]
那这两个while(feof(fp)!=1)和while(!feof(fp))

我觉得它们一样啊  怎么用作条件是怎么不一样???


feof遇到文件结束是返回1吧[em14][/quote]

这样写或许你就知道了:
设:
a=feof(fp)
则:
a!=1

a!=0
当然就是不同的啦:)

4 楼


Starting [url=http://www.toppowerlevel.net]wow power leveling[/url] now, and running until the 17th of March, you can submit a picture of yourself sporting a Wowhead rocket logo [url=http://www.mogxe.com/PowerLevel.php?gid=1]wow power leveling[/url] to our contest page for a chance to win some [url=http://www.toppowerlevel.net/powerlist.php?fid=688]wow power leveling[/url] awesome prizes. We're also offering discounts on Wowhead products in [url=http://www.toppowerlevel.net/buy.php]wow gold[/url] the Wowhead [url=http://www.toppowerlevel.net/powerlist.php?fid=7422]aion power leveling[/url] Store during this contest, [url=http://www.toppowerlevel.net/gamelist.php?fid=7656]aion gold[/url] so now's the perfect time to pick up a t-shirt!Those [url=http://www.toppowerlevel.net]cheap wow power leveling[/url] of you who use the Mac version of the Wowhead Client may have been having some trouble [url=http://www.toppowerlevel.net]buy wow power leveling[/url] uploading your data lately. Well, we've been having a bit of trouble with the [url=http://www.toppowerlevel.net]cheap wow gold[/url] framework that the Mac Client uses to handle updating itself. We've updated the Client so that it works properly, [url=http://www.mogxe.com/PowerLevel.php?gid=21]aion power leveling[/url] but I'm afraid you'll need to download it again.

5 楼

[quote][quote]
那这两个while(feof(fp)!=1)和while(!feof(fp))

我觉得它们一样啊  怎么用作条件是怎么不一样???


feof遇到文件结束是返回1吧[em14][/quote]

这样写或许你就知道了:
设:
a=feof(fp)
则:
a!=1

a!=0
当然就是不同的啦:)[/quote]



a!=1和啊a!=0这个当然不一样啊
[em1][em1][em1]

可是我说的是a!=1和!a啊

6 楼

[quote]
Starting [url=http://www.toppowerlevel.net]wow power leveling[/url] now, and running until the 17th of March, you can submit a picture of yourself sporting a Wowhead rocket logo [url=http://www.mogxe.com/PowerLevel.php?gid=1]wow power leveling[/url] to our contest page for a chance to win some [url=http://www.toppowerlevel.net/powerlist.php?fid=688]wow power leveling[/url] awesome prizes. We're also offering discounts on Wowhead products in [url=http://www.toppowerlevel.net/buy.php]wow gold[/url] the Wowhead [url=http://www.toppowerlevel.net/powerlist.php?fid=7422]aion power leveling[/url] Store during this contest, [url=http://www.toppowerlevel.net/gamelist.php?fid=7656]aion gold[/url] so now's the perfect time to pick up a t-shirt!Those [url=http://www.toppowerlevel.net]cheap wow power leveling[/url] of you who use the Mac version of the Wowhead Client may have been having some trouble [url=http://www.toppowerlevel.net]buy wow power leveling[/url] uploading your data lately. Well, we've been having a bit of trouble with the [url=http://www.toppowerlevel.net]cheap wow gold[/url] framework that the Mac Client uses to handle updating itself. We've updated the Client so that it works properly, [url=http://www.mogxe.com/PowerLevel.php?gid=21]aion power leveling[/url] but I'm afraid you'll need to download it again.
[/quote]

大哥我英文很烂啊[em8]

7 楼

别理那个E文,是广告贴。。。
对于整型的a;
!a就等效于a!=0

8 楼

[quote]别理那个E文,是广告贴。。。
对于整型的a;
!a就等效于a!=0[/quote]

大哥你错了!!
!a绝对不等同于a!=0!!
你自己试!!
!a逻辑上应该和a!=1是一样的
但是我用while(feof(fp)!=1)和while(!feof(fp))怎么就不一样了??

9 楼

这么简单的问题也想不明白?那以后还怎么编程啊?
while(feof(fp)!=1)当没有结束的时候FEOF返回0,0!=1为真,循环继续.
当文件操作结束FEOF返回一个非0整数,可以是2,3,4,5......等等,它们!=1仍然为真,所以文件读完了循环还在继续.
而while(!feof(fp))就不一样了,只要FEOF返回非0值,!FEOF就为假,循环退出.明白了不?

10 楼


还是你强啊!!一点就通[em2]

我忘了读到结束不一定是1啊- -!

我来回复

您尚未登录,请登录后再回复。点此登录或注册