回报价值? [英] return value?
问题描述
我一直在使用带有while循环结构的fgetc和fputc来复制
文件。它看起来工作正常但事情是我总是检查fgetc的RV
并且它总是-1。如果程序不正常我得-1。 -1总是
错误代码并不总是意味着失败吗?
比尔
I have been using fgetc and fputc with a while loop construct to copy
files. It seems to work fine but the thing is I always check for fgetc''s RV
and it''s always -1. If the program doesn''t work right I get -1. Is -1 always
an error code and doesn''t it always mean failure?
Bill
推荐答案
Bill Cunningham说:
Bill Cunningham said:
我一直在使用带有while循环结构的fgetc和fputc进行复制
文件。它看起来工作正常,但事情是我总是检查fgetc的'
RV,它总是-1。如果程序不正常我得-1。是-1
总是错误代码并不总是意味着失败?
I have been using fgetc and fputc with a while loop construct to copy
files. It seems to work fine but the thing is I always check for fgetc''s
RV and it''s always -1. If the program doesn''t work right I get -1. Is -1
always an error code and doesn''t it always mean failure?
代码,请。
-
Richard Heathfield< http:// www.cpax.org.uk>
电子邮件:-http:// www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
Code, please.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
8月27日凌晨4:17,Bill Cunningham < nos ... @nspam.comwrote:
On Aug 27, 4:17 am, "Bill Cunningham" <nos...@nspam.comwrote:
我一直在使用带有while循环结构的fgetc和fputc来复制
文件。它看起来工作正常但事情是我总是检查fgetc的RV
并且它总是-1。如果程序不正常我得-1。 -1总是
错误代码并不总是意味着失败?
I have been using fgetc and fputc with a while loop construct to copy
files. It seems to work fine but the thing is I always check for fgetc''s RV
and it''s always -1. If the program doesn''t work right I get -1. Is -1 always
an error code and doesn''t it always mean failure?
否。这是EOF(< stdio.hand others)。在你的实现上,EOF
发生在-1。
No. It''s EOF (<stdio.hand others). On your implementation, EOF
happends to be -1.
我一直在使用带有while循环结构的fgetc和fputc来复制
I have been using fgetc and fputc with a while loop construct to copy
>文件。它似乎工作正常
>files. It seems to work fine
你看过复制的文件了吗?他们是否填写了正确的
字符或-1?如果它们填充了正确的字符,那么
fgetc()是* NOT *总是返回-1。
阅读有关fgetc()的文档与你的编译器一起来。
Did you look at the copied files? Are they filled with the correct
characters or -1? If they are filled with correct characters, then
fgetc() is *NOT* always returning -1.
Read the documentation on fgetc() that should have come with your compiler.
>但问题是我总是检查fgetc'的RV
并且它总是-1。
>but the thing is I always check for fgetc''s RV
and it''s always -1.
EOF在您的系统上的值可能为-1。
EOF probably has the value of -1 on your system.
>如果程序没有我工作正常我得-1。 -1总是
错误代码并不总是意味着失败?
>If the program doesn''t work right I get -1. Is -1 always
an error code and doesn''t it always mean failure?
我不认为EOF是错误代码。您可以使用
ferror()将EOF作为返回值后测试是否发生了
错误。如果你继续阅读文件,你通常会得到EOF(真正的
文件结尾)(非普通文件除外)/ b $ b / b / dev / zero或/ dev / random)。将EOF放在错误的地方
可能表示错误。
I don''t consider EOF to be an error code. You can test whether an
error occurred after getting back EOF as a return value by using
ferror(). If you keep reading a file, you''ll usually get EOF (real
end-of-file) eventually (with exceptions for non-ordinary files
like /dev/zero or /dev/random). Getting EOF in the wrong place
might indicate an error.
这篇关于回报价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!