In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use the feof function in C language. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
I. brief introduction of feof function
Feof is a c language function that can be used to judge both binary and text files. Feof (fp) has two return values: if the file ends, the function feof (fp) has a value of 1, otherwise it is 0.
EOF is the file with the end of the file flag. In a text file, the data is stored in the form of ASC Ⅱ code values of characters. ASC Ⅱ codes range from 0 to 255, and-1 is not possible, so you can use EOF as the end flag of the file.
The-1 value occurs when the data is stored in a file in binary form, so EOF cannot be used as the closing flag of the binary file. To solve this problem, ASCI C provides a feof function to determine whether the file is finished or not.
The statement is as follows:
# include # include / * * description: detect file Terminator * * Parameter: * [in] stream: file pointer handle * * return value: if the file ends, a non-zero value is returned, otherwise 0 is returned, and the file Terminator can only be cleared by clearerr * / int feof (FILE * stream) II. Feof function practice / * / / @ Author: ape programming / / @ Blog (personal blog address) : www.codersrc.com//@File:C language tutorial-C language files read and write feof functions / / @ Time:2021/07/22 07:30//@Motto: you can't reach thousands of miles without long steps. Do not accumulate a small stream can not become a river and sea, the program of wonderful life needs to unremittingly accumulate! / * / # include # include int main (void) {FILE * stream / * open a file for reading*/ stream = fopen ("DUMMY.FIL", "r"); / * read a character from the file*/ fgetc (stream); / * check for EOF*/ if (feof (stream)) printf ("We have reached the end of file\ n"); / * close the file*/ fclose (stream); return 0;}
Note: feof determines the end of the file by reading the function fread / fscanf / fgetc and other return errors to identify, so to determine whether the end of the file should be judged after reading the function.
For example, when a file is read in a while loop, if the judgment is made before the function is read, a memory error may occur if the last line of the file is a blank line.
This is the end of the article on "how to use the feof function in C language". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.