 Hello friends, I am Sanjay Bota. I am welcoming you on Sanjay Bota Tech School. In this video, I am going to explain how you can read character on file and how you can write character into a file. So this program will be based on file handling in C and that will tell you the process of file handling in C. Before starting, if you go to the description of this video, so you will find links of various areas related to C language. Now to explain this process, I will be writing two separate programs. So my first program will be reading from user and writing it into a file. So that will be first program. So first program will be reading from user and writing it into a file. And user will be providing all the elements into a file. Second program will be reading any form of file and storing it into another file. So let's say it is file one, so file one, file two. So that input which will be received from user will go into file one. Then I will be opening file one and storing its content into file one. And all this process will be dependent on how it will be written and it will come. So let's begin with this first program. So first of all, inside build function, I'm going to pick up a file pointer. Then an integer array, let's say its size is 10, variable i, so that we can process a loop. Then I am going to open a file. So here you can see we need to write the input which is received from user into this file. So the file one should be opened into w mode. So here I am writing the name of file as file one.exe and I am opening it into w mode. So w mode opens a file in live mode. If file is not available, it will be created automatically. And if file is already there, so its previous contents will be erased automatically. So use this w mode very carefully. If you want to preserve the previous data as well. So instead of using w, you can use a mode that is for appending contents. And this name you can use any name, whatever you want. And txt is for notepad, so the editor we all use. So this is name of file and this is mode. Now I am going to check if fp double equals to none. And if this condition is true, so I am going to print find not found. And to exit, I am going to terminate this process. So you might be thinking why I implemented this condition. Because I am using w mode, if file is not available, it will be created. So why I am checking at txt none. So there is a reason. Let's say your memory is built completely. The data is full. There is no space. So in that scenario, if your file is not available. So will new file be created or not? So your answer will be no. So for example, if you are using your mobile phone and your memory is full. And you want to take a picture. So will your phone be clicking a picture and sending it into memory? No. It will say erase some previous picture or erase something from the memory so that new pictures can be clicked and saved. So similarly, if your memory is full, then w mode will not be able to create new files and your file pointer will be having null. So that's why in every case, if you are using lead mode, w mode, a mode, whatever mode you are using always use this condition so that you can check whether file pointer is having a particular address or null. So if it is having null, so program will be terminated here. So unnecessarily the remaining statements will not be any. Now after this, I can write a printer statement. So it will display a message. Enter values to read these values. I'm going to write a form which will repeat 10 times. So this form will be 10 values from user through this scan. So this is very simple. So I hope if you are watching this video related to filing, so you are familiar with area also. So you can understand this process. It is very easy, which is really 10 values and all the values will be stored into N. Now for the requirement, this requirement is completed. We have received input from user. Now we need to store that received input into file one so that that file can be opened in lead mode and that content will be stored into file. And this is the benefit of file handling. If you want to store your data permanently, then only are you in file handling concept otherwise. So whatever I received from user now, I want to store that property into file and that to music. So I'm going to use a predefined function that is f right. So as right will store your complete area without it affecting any group in a single state. So here you need to pass name of area. Then signs of individual location. So our area is of individual type. So here I'm passing size of it. So the size of is also predefined. So it will calculate size of data type. Then her argument will be number of elements. So this area contains total 10 elements. That's why I'm passing and here if your area is containing more elements, you can change this. And lastly, five point. So here you can see this five point is opening this five one. So if I'm writing FB here, it means this area will be stored into this file. And after this, you can write as close and FB. So this way, I hope you understood how we can read area from user and through a single F right statement. How we can write all this elements which are available into a file. So this area will be storing into this file. Each block is having size of a skin. And this is the quantity that will be stored into this file. So this first process is completed. We successfully received input from the user. And we store that area into file with the help of FB. Now coming on to the second process. So here we need to maintain two points, five one and five two. And five one, I need to open and read more. And five two, I need to open it W. So now I'm going to erase these statements. So I will be modifying the beginning steps and then you will see how I can read the contents of five one without any new and without any new those contents will be stored into five new. So here I need to open two files. So. So now I'm going to do your two five pointers. So let's say F one and five point F two. And any same, this will not be required. The label will not be required. Then this is F one, F open five one. And this time mode will be read, right? Why do I need to open its mode will be done. So when you will be executing previous program that I explained. So that program will create this five one. And after the creation of that five, we can open that in the right. And this file is open in double mode. So if it is not available, it will be created. But for further movement, we need to check this condition. This time I'm checking it for both. If F one is null, then also it will be true. If F two is null, then also it will be true. If both are not containing them, then this condition will be false and even statement. So this is very important because if five is not open successfully, then there is no need to execute limiting statements. So we can write five not found or five not open and exit. So this way I hope you understood the process here. Now we need to add a file and we need to write that into five two. So only two statements will perform this operation. So if you want to read, add it on five. So you can use at right. So every then a name of a size of a comma 10 and F one. So this time every function will be really data from F one. And that will be stored into a. So F one will store your data into a and size of it. So we need to receive integer and how many elements we are going to receive. So through previous program we store 10 elements. That's right. And that information will be available into this area. Now we can use F right again. And same area will be stored into. By using F right. This way. So here you can see every is a single statement, which is really old. And right is also a single statement, which is writing. And five is this. Right. So I hope you understood how we can write a data. That is received from five one into five two. And then two with the help of. And then you can write. As close all. So that all files. Those are open in your program. So this is the process through which I hope you understood how we can read. And how we can write. So I explain you to. So implement these programs in your laptop so that you can understand this process. And if you want to watch more programming related videos, go to description of this video. There you will find lots of playlist. Links related to see like this video. So you follow that. And thank you for watching this.