avatar
ask a question about C# Java - 爪哇娇娃
z*i
1
读数据从文件中,
input=fopen(filename,"rb");
while ( (c=fgetc(input)) != EOF )
{
}
可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?
avatar
f*g
2

use fstat/stat to count your file's size. read
the size of byte instead of checking if EOF is reached.

【在 z********i 的大作中提到】
: 读数据从文件中,
: input=fopen(filename,"rb");
: while ( (c=fgetc(input)) != EOF )
: {
: }
: 可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?

avatar
g*e
3
what is the type of c? int or char?
if char, you get into trouble because
-1 is same as 0xff in char.

【在 z********i 的大作中提到】
: 读数据从文件中,
: input=fopen(filename,"rb");
: while ( (c=fgetc(input)) != EOF )
: {
: }
: 可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?

avatar
s*e
4
agree, this code is wrong.

【在 g*******e 的大作中提到】
: what is the type of c? int or char?
: if char, you get into trouble because
: -1 is same as 0xff in char.

avatar
Q*g
5
what's the data type of variable c? if it's int, the code should be fine.
if it's char, you may get a problem coz you can not differentiate EOF
and 0xff. the following paragraph is extracted from GNU C library:
These functions return an int or wint_t value (for narrow and wide stream
functions respectively) that is either a character of input, or the special
value EOF/WEOF (usually -1). For the narrow stream functions it is
important to store the result of these functions in a variable of type i

【在 z********i 的大作中提到】
: 读数据从文件中,
: input=fopen(filename,"rb");
: while ( (c=fgetc(input)) != EOF )
: {
: }
: 可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?

avatar
z*i
6
Thank, already done with Java, will try later for C.
My former definition is
char c, changing to unsigned int c works. Thank you

【在 s*****e 的大作中提到】
: agree, this code is wrong.
avatar
b*k
7
while (!feof(input)) c=fgetc(input);

【在 z********i 的大作中提到】
: 读数据从文件中,
: input=fopen(filename,"rb");
: while ( (c=fgetc(input)) != EOF )
: {
: }
: 可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。