0

I have tried to read serveral files into buffer. Most of them succeed,but one of them didn't. This always happen when reached (end of file)-1.

Part of the code:

char buf[1024];
long validbyte,filesize=0;
while(!feof(fp)){
    validbyte=fread(buf,sizeof(char),sizeof(buf),fp);
    filesize++;
}
printf("File size is : %ld",filesize);
printf("validbyte is %ld\n",validbyte);

The actually file size is 1044480 kb,but "filesize" is always display 1044481,and fread() return 0 at (end of file)-1 . The result picture

That file is ubuntu-14.04.4-desktop-amd64.iso ,which download at ubuntu offical website.

So what happened when fread() return 0 and not reach the end of the file?

GGininder
  • 3
  • 3

0 Answers0