What Is EOF (End Of File)? Examples with PHP, C++, C, Python, Java – POFTUT

What Is EOF (End Of File)? Examples with PHP, C++, C, Python, Java

Files contain different types of data like text, image, video, headers, graphics, etc. All these data are stored in different encoding and formatting techniques but every file has an end which is named End Of File which sets the last by of the given file. In this tutorial, we will learn the meaning of the End Of File and relation with the popular programming languages like C, C++, PHP, Java, Python.

What Is End Of File?

End Of File is the special data or delimiter which will set the end of file for a specific file. This file contains different types of data from text to image but the end of the file is the same for all of them. End Of File can be also expressed as EOF in a short form. EOF is also used in different programming languages in order to express and check the end of the file.

Checking the end of the file is important especially developing applications. While reading a file to process, print or view we need to check the end of file in some cases especially in low-level operations.

End Of File In C and C++

C and C++ provide different file operation functions. We can use EOF value in order to check the end of the file which can be used to check different functions return value. EOF stores the -1 where a file operation function will return -1 when the end of file is reached.

In the following example, we will read the file named myfile.txt with the getc() function which will read a single character from a given file for each time. We will check the EOF after every read operation.

LEARN MORE  fopen() Function Usage In C and C++ with Examples

End Of File In PHP

PHP provides feof() function in order to check the end of the file. When there are some bytes or not end of file the feof() function will return false and the provided iteration will continue till to end of the file.

End Of File In Java

Java programming language provides different functions in order to read, write files. In Java when a file is read the value generally stored in a variable like a String. If the end of the file is reached the returned value will be a null which is simply nothing. We can check the end of the file if the returned value is null like below.

End Of File In Python

In Python, there is no specific EOF function but we can use some techniques like checking line we read and determine the EOF. We will read the file line by line with while loop. If the end of the file is reached the returned line value will be null.

LEARN MORE  How To Move End of File and Line In Vi or Vim?

echo '
'

Leave a Reply

Your email address will not be published. Required fields are marked *