Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect end-of-file when using open/read?

Tags:

c

linux

I am using open/read functions, there's feof for fopen/fread to detect end-of-file, what's the equivalent way for open/read?

like image 968
Mickey Shine Avatar asked Mar 21 '12 14:03

Mickey Shine


People also ask

How do you detect the end of a file?

feof() The function feof() is used to check the end of file after EOF. It tests the end of file indicator. It returns non-zero value if successful otherwise, zero.

What does read () return at end of file?

The read() method of the input stream classes reads the contents of the given file byte by byte and returns the ASCII value of the read byte in integer form. While reading the file if it reaches the end of the file this method returns -1.

How do you indicate EOF in Python?

Use Walrus Operator to Find End of File in Python It is denoted by := . This operator is basically an assignment operator which is used to assign True values and then immediately print them.

Can we use EOF in Python?

Python doesn't have built-in eof detection function but that functionality is available in two ways: f. read(1) will return b'' if there are no more bytes to read. This works for text as well as binary files. The second way is to use f.


1 Answers

From man read:

On success, the number of bytes read is returned (zero indicates end of file), ...

like image 173
hmjd Avatar answered Oct 11 '22 03:10

hmjd