Fread returns a value of 0 feof. The returned value is 16.

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.