Feof () function reading file and EOF Terminator mark Problems

Source: Internet
Author: User

The TXT files in windows are stored in the form of ASC ⅱ code values. As we all know, the range of ASC 2 code is 0 to 255. values in other ranges cannot be identified. Therefore, values like-1 cannot be converted into corresponding characters that exist in text files. But for binary files,-1 can indeed appear.

The feof () function is used in C/C ++ to determine whether the current file to be operated ends. If the file has ended, the return value is 1; otherwise, 0 is returned. the principle of determining whether a file ends is different from the EOF () function in the database. Feof () is used to determine whether to end the read object based on whether the content is null. The EOF () function is used to determine whether the position of the current Object Pointer has reached the end of the object. This means that feof () is determined based on the content, while efo () is determined based on the position.

The EOF is the end mark of a file. Its value is-1.

Definition: # define EOF (-1)

Definition: # DEFINE _ ioeof ox0010

Definition: # define feof (_ stream)-> flag & _ ioeof)

Feof () is used to determine whether the end of the last file operation is completed. After feof () reads the last character in the file, it will continue to read the content at the next position. If it is null, it indicates that it has reached the end of the file. This will set _ stream-> flag to _ ioeof. To make feof () return 1.

EOF can only be used to determine whether a text file ends. At this time, it checks whether the read character is equal to EOF to determine whether the file ends and feof () does not appear () the problem of determination (the target file will output a byte of content than the source file ). Sometimes EOF cannot be used to replace feof () because it is willing to read the file, an error will also return-1.

 

 

 

 

 

 

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.