 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to explain how you can use fprintf function in pie handling so that you can store data into a file. So fprintf is similar to printf. So if we use printf, we can display integer, float character or any kind of data on an output screen. So similar to printf, if you use fprintf so that you can store int, float character or any other data type value into a file. So before I start writing the program, I just want to share one information. If you go to description of this video, you will find links of various playlists related to C language so you can watch them too. Now I am going to write a program in which I will show you how we can store integer data into a file, how we can store data into a file. So you will realize fprintf is similar to printf but the difference is printf displays output on console whereas fprintf stores output on a file. So I am starting the code. So first of all I am going to declare a file pointer, then integer variable n1, float variable n2, then I am going to open a file. So let's say file name is data1.exe and I am going to open it in w mode. And if we use w mode it means if file is not available it will be created automatically. And if you want to specify a particular path like this file should be created on a particular location. So you can write like this so c colon slash then your folder name and then your file name. So this path you can follow. So first you need to mention that write location, then folder location and then file location. And let's say if your file is not open properly so we can check this. If file pointer is equals to null it means file is not open successfully. So if file is not open it means there is no requirement to write something into that file. If this file is not available then where you will write the data. So before writing the data we need to check, we need to apply a validation condition that file is available or open or not. So if fp that is file pointer is equals to null then we can display a message on console. File not found and after this we can use exit function which will terminate the execution of the program. So if file is not found then from here a program will be terminated from this point and after this whatever the statements will be they will not be executed. And this is important because if file is not opened or not found so there is no requirement to execute statements which are written after this. And if file is available then fp will not be equals to null so it means this condition will be false and the statements which are written after this will be executed. So let's say I am writing print f enter number or enter your age so that it will be in either form so over 70 and percent n1. So the age of user will be available into this n1 variable. Now I am going to use this f printer function so that I can store the value which is available into n1 variable inside a file. So I need to use fprintf and file pointer through which our file is linked so file pointer is linked with this file. So fp, then let's say backslash n for 70 n1. So this way the number which is available into n1 will be stored on the back of this format specified into this file. So now your n1 value will not be displayed on console rather it will be stored into a file which is linked with this fp. So let's say this is your data 1 file so your age will be stored like this. Now if you want to need enter your salary and let's say this time we are using percent f and n2 variable. So here you can see n2 is appeared as slope so we need to use percent f so now if I want to store the value so I can use fprintf again fp, backslash n this time I need to use percent f, n2. So this way whatever value available into n2 will be stored inside this file pointer. So let's say user entered 1000 to 1000 will be stored here and it is a flow value so 0.00 will get circuit off. So this way you saw fprintf can store integer, flow, care, develop on any kind of value into a file. So after these operations at last you can use your file and then you can use your main function. So this way I hope you understood how we can use fprintf function so that we can store any kind of data into a file using the concept of file handling. And I hope you understood whatever I explained in this video so you can try this program in your laptop so that you can see whether the data is written into your file or not and specify a proper path so that you can find this file where it is located and if you want to watch more programming related videos so you can go to my channel and there are various videos are available or you can go to description of this video so you will find various links of playlist related to C language so we will follow them. So thank you for watching this video.