主题:[讨论]搞文件时遇到的怪现象
ccmike98
[专家分:80] 发布于 2010-07-26 23:16:00
while(feof(fp)!=1)和while(!feof(fp))从逻辑上不是一样大吗[em10]
怎么实际用起来不一样啊????
回复列表 (共11个回复)
沙发
alweeq86 [专家分:1170] 发布于 2010-07-27 08:52:00
while(feof(fp)!=1)和while(!feof(fp))
读取到文件尾部是返回-1
只要feof不是0 !feof的值 =0
想想吧
板凳
ccmike98 [专家分:80] 发布于 2010-07-27 10:12:00
那这两个while(feof(fp)!=1)和while(!feof(fp))
我觉得它们一样啊 怎么用作条件是怎么不一样???
feof遇到文件结束是返回1吧[em14]
3 楼
cgl_lgs [专家分:21040] 发布于 2010-07-27 10:59:00
[quote]
那这两个while(feof(fp)!=1)和while(!feof(fp))
我觉得它们一样啊 怎么用作条件是怎么不一样???
feof遇到文件结束是返回1吧[em14][/quote]
这样写或许你就知道了:
设:
a=feof(fp)
则:
a!=1
与
a!=0
当然就是不同的啦:)
4 楼
xingxing01 [专家分:0] 发布于 2010-07-27 15:53:00
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 楼
ccmike98 [专家分:80] 发布于 2010-07-27 16:17:00
[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 楼
ccmike98 [专家分:80] 发布于 2010-07-27 16:19:00
[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 楼
cgl_lgs [专家分:21040] 发布于 2010-07-27 23:24:00
别理那个E文,是广告贴。。。
对于整型的a;
!a就等效于a!=0
8 楼
ccmike98 [专家分:80] 发布于 2010-07-28 14:41:00
[quote]别理那个E文,是广告贴。。。
对于整型的a;
!a就等效于a!=0[/quote]
大哥你错了!!
!a绝对不等同于a!=0!!
你自己试!!
!a逻辑上应该和a!=1是一样的
但是我用while(feof(fp)!=1)和while(!feof(fp))怎么就不一样了??
9 楼
强强 [专家分:4740] 发布于 2010-07-28 19:22:00
这么简单的问题也想不明白?那以后还怎么编程啊?
while(feof(fp)!=1)当没有结束的时候FEOF返回0,0!=1为真,循环继续.
当文件操作结束FEOF返回一个非0整数,可以是2,3,4,5......等等,它们!=1仍然为真,所以文件读完了循环还在继续.
而while(!feof(fp))就不一样了,只要FEOF返回非0值,!FEOF就为假,循环退出.明白了不?
10 楼
ccmike98 [专家分:80] 发布于 2010-07-28 21:58:00
还是你强啊!!一点就通[em2]
我忘了读到结束不一定是1啊- -!
我来回复