WriteProgramTo read from the binary file, but when I read 11396 bytes, fread returns 0, its feof (FP) = 16
Baidu Encyclopedia:
Feof (FP) has two return values: if the file ends, the feof (FP) value of the function is a non-zero value; otherwise, it is 0.EOF indicates the end of a text file. In a text file, the data is the characters of ASC ⅱCodeThe value format is stored. The ASC ⅱ code of a common character ranges from 32 to 127 (decimal), and The hexadecimal code of EOF is 0x1a (decimal is 26 ), therefore, you can use EOF as the end mark of the file. When you store data in binary format to a file-So EOF cannot be used as the end mark of the binary file. To solve this problem, asci c provides a feof function to determine whether the file is over. The feof function can be used to determine both binary files and text files. The "feof ()" function in the "c" language is totally different from the "EOF ()" function in the database. The "EOF ()" function in the database reads the position of the current pointer. The "feof ()" function in the "c" language returns the last "read operation content ". After many years of mixing "location and content", the concept is similar.
The first sentence is really misleading. I did not finish the file, but returned non-0.
Continue reading. If the read result is 0x1a or feof is not 0, I will check the 11396-8 bytes, Which is 0x1a.
What should we do?
My FP is so fopen
Fopen (This-> Relativeroadidfilename,"R");
Change R to RB. Finally, I understood that B was useless .. B should be useless in Linux. So this is only true in a non-POSIX environment.
This is what fopen Baidu encyclopedia says.
Therefore, feof in Baidu Encyclopedia should have three return values: 0, 1, not 0, and 1.
There is also the second fread parameter. If there are not so many reads, the return value of fread may be less than count. See:
Http://yijiuzai.blog.163.com/blog/static/1037567272010417103312770/