 Hello everyone, my name is Nikhil Gajjam, I am working as assistant professor in department of computer science and engineering in Valchand Institute of Technology, Solapur. In today's session, we will learn introduction to file handling in C. Learning outcome of this session is at the end of this session, student will be able to access file using different file opening modes. So this is introduction to file, first we will consider what is the need of storing data into the file. When you write any program in C, generally we store values in variables. So after execution of program, whatever values you stored in variable, those are vanished and destroyed and memory allocated for those variables are deallocated. So better to use file or database to store the values. So there are two ways in which we can store the values of variable permanently and those are either we store those values in file or in database. So accessing database is faster because of indexing in database. But in this session, we will consider only file. So requirement of file storage are to store data permanently into the file and second one to access data with ease. So there are many file handling functions present in C like get C put C get S put S or F read F write likewise. So next one is file pointer. So file pointer is a pointer pointing to a file, particular file which is open for reading or writing purpose. Syntax is file star fp, fp is any variable name which is a pointer to a file. So next function is f open, f open is a function used for opening a file either for reading or writing purpose. So f open function except two parameters, first one is file name, second one is file opening mode. So written type of f open is a file pointer. So these are six basics basic file opening modes used in C. So first one is r, w, a, r plus, w plus, a plus, these are related to text. So similarly six other modes are there which are related to binary files. So these six file opening modes are used for text files. So we will consider r, r is a text file used for reading mode, w opens or creates a text file in writing mode, a opens a text file in append mode, r plus opens a text file in both reading and writing mode, w plus opens a text file in reading and writing mode, a plus opens a text file in reading and writing mode. We will see one by one these file opening modes in detail now. First one is r mode. R mode is used for only reading purpose. With r mode writing is not possible, it returns null if file is not present means if you want to open a file which is not present and if you have opened that file in r mode it will return a null. If you open a file in r mode if it is present then file pointer will point in the beginning of the file. So syntax same fp equal to f open input dot txt is a file which I want to open for reading purpose and file opening mode as a second argument I will pass r. Text file opening mode is w. It is used for writing purpose. Reading is not possible with w mode. If file is not present it will create a new file. This is a difference between r mode and w mode. In r mode it will return null but in w mode if file is not present and you have opened that file in w mode it will create a new file and now what happen if you open the file which is already present and you have opened that file in w mode then if file is already present then content of old file is truncated. Truncated means deleted and a file is opened in w mode then file pointer will point at the beginning of the file. So example fp equal to f open input dot txt is the file which I want to open in w mode. So second argument I have passed as w. File opening mode is a mode or append mode. It is used for appending purpose. If file is not present it will create the new file. If file is already present then content of old file will be truncated. Truncated means deleted and file pointer will point at the end of file. Similarly a is used for appending a new content at the end of the file. So file pointer will point at the end of the file. So example fp equal to f open input dot txt is the file which I want to open in append mode. So second argument I have passed for f open function as a a. Now these are advanced file opening modes r plus w plus and a plus are advanced then basic r w and append mode. R plus is used for reading purpose and writing purpose both. And it returns null if file is not present. And file pointer will point at the beginning of the file. So reading and writing both are possible with r plus mode. So example fp equal to f open input dot txt and r plus is a file opening mode I have passed as a second argument. Next one w plus mode used for writing purpose and reading purpose. So major purpose is writing. And reading is also possible with w plus mode. Now if file is not present it will create a new file. So difference between r plus and w plus is same. In r plus it will return a null in w plus it will create a new file. If file is already present then content of old file will be truncated then deleted. And file pointer will point at the beginning of the file. So example fp equal to f open input dot txt comma w plus. Now think and write what is the difference between r plus mode and w plus mode. Answer is both r plus mode and w plus mode used for reading and writing purpose. But the difference is in r plus if file is not present and you have opened that file in r plus mode then it will return a null. In w plus mode if file is not present and you have opened that file in w plus mode then it will create a new file. So again in r plus a new file is not created but in w plus mode it will create a new file. Another difference is in r plus if file is already present old content will not be deleted. But in w plus if file is already present and you have opened that file in w plus old content will be deleted. Now last file opening mode is a plus mode. It is advanced version of a mode append mode. A plus mode is used for appending a new content at the end of the file as well as a plus can be used for reading purpose also. If file is not present it will create a new file. If file is already present then the content of old file will be deleted. And file pointer will point at the end of the file because new content will be added at the end of the file. So example fp equal to f open input dot txt a plus is a file opening mode I have passed. So these are different references I have used for this session.