 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you the difference between write and append mode available in file handling in C programming. Before starting, you can note how you can search my YouTube channel. You can type my name Sanjay Gupta in YouTube search bar. My channel will be available there. You can watch various programming related videos here. Now, first I am going to demonstrate you the use of w-mode and then I will be discussing the use of a-mode. So first I am including a header file stdio.h, another header file stdlib.h. Then I am going to define main function. Inside main function, I am declaring an integer variable that is n. Then I am going to declare a file pointer with the help of file data type. This file data type is predefined. Now I have to open a file by calling fopen function. So here I am passing the name of file that is number.txt and I am using w-mode. So I am trying to open number.txt file with w-mode. So in case of w-mode, if this file is not present in the system, that is number.txt, w-mode will create this file automatically in the system. Now I have to check whether fp has received address of number.txt or not. So if it is not receiving the address, then file pointer must be equal to null. So then I can print the message error cannot open file. So this message will be displayed on output screen and then I can call exit function. So this exit function terminates execution of the program. If file pointer is receiving a particular address, then this if condition will be false. Then I can type another statement. So I am writing printf which will display the message enter a number. So this message will be displayed on output screen to receive the number from user. I am calling scanf. So the entered number will be stored inside n variable through scanf function. Now I am going to write this value n into the file number.txt. So I am calling fprintf and I am passing fp comma slash n, sorry, percenty slash n and then n. So this way the value of n will be stored inside fp. fp is pointing to number.txt. So I can say value of n will be stored inside number.txt through this f printer function. So after completion of f printer function operation, I can call fclose. So fclose function closes the opened file. So file is opened through this fp pointer. So I have passed this pointer so that file can be closed and then return 0. So you can notice that I have used w mode in this program. First I have to check whether this number.txt is available in the system or not so that we can see whether it is created automatically or not. So location of this file will be ctcnbin. So first I have to open c drive then tc folder and then bin folder. So I have already opened bin folder. So you can see the path I have first opened c drive then tc folder and then bin folder. Now I am pressing n. So you can see the file which starts from letter n available here. Only four files are present and number.txt is not available here. Now I am going to execute this code. You can see it is asking for a number. I am entering 10. So I have entered 10 and after entering 10 nothing is displayed on output screen. Now we have to check bin folder again whether number.txt is created or not. So you can see here number.txt is created. Now I am going to open this file. You can see it is having 10 as input. So the 10 which I have entered on output screen it is perfectly stored in this number.txt file. Now again I am executing this code. This time I am going to enter 20. So again I have entered 20 and it is not showing anything after that. So moving to bin folder. Now again I am opening number.txt file. You can see 10 is replaced with 20. So this is the effect of w mode. In case of w mode, whenever you execute the program, file is open, sorry, whenever you execute the program using w mode, every time whenever you execute the program it erases the previous contents of the file and it places the new content into the file. So first I have executed this program then I entered 10. So number.txt was having 10 as the data. Then when second time I have executed the program I entered 20. So w mode replaced that 10 with 20 because w mode stores the latest output in the file. Previous data will be erased, sorry, previous data automatically erased while you are using w mode. Now if you want to store all previous data into the file then in place of w you can prefer a mode. So a means append. So this is the advantage of append mode. Whenever you execute the program the result will be stored inside the file automatically. So now I am going to execute this program twice. So I am executing this program. I am entering 30. So this time I have executed this program only first time. Again I am executing this code and I am entering 40. So first time I entered 30, second time I entered 40. Now moving to the bin folder I am opening number.txt. So its previous value was 20. Now see it is having 20, 30 and 40. So because I am using a mode. The previous data is preserved in this file and the new data is appended at the end of file. So if you want to preserve all the previous data's which are available in a particular file then you can prefer a mode. And if you want that previous data must be erased then you can prefer w mode. So this is the difference between w and a mode. w mode keeps only the latest data or you can say latest output of the program whereas a mode stores all the previous data as well as new data generated by the c program. So this is the difference between both the modes w and a. I hope you have understood both the modes and their differences. I have demonstrated you both practically. So you can implement this in your system so that you can understand how w and a modes are working in c programming with the help of file handling. If you want to watch more programming related videos you can search my name Sanjay Gupta in YouTube search. The channel will be available there. You can watch various programming related videos there. Thank you for watching this video.