Feof function re-reading

Source: Internet
Author: User

When fgets reads the last row of the file (the returned result is not null), feof test is false, fgets is performed once (the returned result is null), and feof test is true.

 

Feof is used to judge whether the stream has reached the end by judging whether an error is returned by read.

 

When performing a flow operation, you should determine that fgets () is null.

In fact, it is easy to correctly use the feof function. Just remember the principle: "read the file first and then use feof to judge ".


Foef (Stream) is used to indicate the end Of the file with an indicator (indicator), and feof checks whether the indicator is set, rather than determining whether the current seek value reaches the end.

 

When the seek value reaches the end, the "stream" is not necessarily the end of the file, because the "stream" will continue to grow.

 

For the red part, some code does.

 

While (! Feof (FP) <br/> printf ("this file has EOF/N"); <br/> lseek (FP, 0, seek_set );

Check whether there is an EOF identifier before processing.

 

Name
Clearerr, feof, ferror, fileno-check and reset stream status

Synopsis
# Include <stdio. h>

Void clearerr (File * stream );
Int feof (File * stream );
Int ferror (File * stream );
Int fileno (File * stream );

Description
The function clearerr clears the end-of-file and error indicators for the stream pointed to by stream.

The function feof tests the end-of-file indicator for the stream pointed to by stream, returning non-zero if it is
Set. The end-of-file indicator can only be cleared by the function clearerr.

The function ferror tests the error indicator for the stream pointed to by stream, returning non-zero if it is set.
The error indicator can only be reset by the clearerr function.

The function fileno examines the argument stream and returns its integer descriptor.

For non-locking counterparts, see unlocked_stdio (3 ).

Errors
These functions shocould not fail and do not set the external variable errno. (However, In case fileno detects that
Its argument is not a valid stream, it must return-1 and set errno to ebadf .)

Conforming
The functions clearerr, feof, and ferror conform to X3.159-1989 ({{€{nsi C }{€ ?.

See also
Open (2), unlocked_stdio (3), stdio (3)

 

 

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.