z********i 发帖数: 60 | 1 读数据从文件中,
input=fopen(filename,"rb");
while ( (c=fgetc(input)) != EOF )
{
}
可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗? | f*****g 发帖数: 31 | 2
use fstat/stat to count your file's size. read
the size of byte instead of checking if EOF is reached.
【在 z********i 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 读数据从文件中, : input=fopen(filename,"rb"); : while ( (c=fgetc(input)) != EOF ) : { : } : 可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?
| g*******e 发帖数: 14 | 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 读数据从文件中, : input=fopen(filename,"rb"); : while ( (c=fgetc(input)) != EOF ) : { : } : 可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?
| s*****e 发帖数: 21415 | 4 agree, this code is wrong.
【在 g*******e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : what is the type of c? int or char? : if char, you get into trouble because : -1 is same as 0xff in char.
| Q**g 发帖数: 183 | 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 读数据从文件中, : input=fopen(filename,"rb"); : while ( (c=fgetc(input)) != EOF ) : { : } : 可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?
| z********i 发帖数: 60 | 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : agree, this code is wrong.
| b****k 发帖数: 10 | 7 while (!feof(input)) c=fgetc(input);
【在 z********i 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 读数据从文件中, : input=fopen(filename,"rb"); : while ( (c=fgetc(input)) != EOF ) : { : } : 可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?
|
|