 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can use fprintf function 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. My channel will be available there. You can watch various programming related videos here. Now I am going to demonstrate you the use of fprintf. fprintf is a predefined function which can write integer, float, characters and string, any kind of value into a file. So for demonstration purpose I am going to write a code in front of you. First I am including a header file that is stdio.h. Another header file is stdlib.h. Then I am going to define main function. Here I am declaring a file pointer. Now I am going to open a file whose name is dammo.txt and I am going to open it in w mode. So if dammo.txt is already available that its contents will be erased because mode is w and if dammo.txt is not available it will be created automatically and this file will be created in ctcn bin folder. Why so? Because the source code is stored in test.c file and this c.c file is stored in bin folder. So that's why dammo.txt will be created in ctcn bin folder automatically. If your source code is saved in another location then this dammo.txt will be created on that location automatically. Now I have to check whether this file is opened successfully or not. So for that purpose I am writing this if statement. It is checking fp is null or not. So if fp is null it means file is not opened successfully. So I can write this printf statement which will display error cannot open file and exit will terminate execution of the program. But if file pointer is containing an address then the save condition will be false. So now I can call f printf function. It will have three arguments. First is file pointer. Second one is format specifier and third is value. So here I am going to write a character into a file. I have closed fp. So first I am going to demonstrate you how we can write characters. Then I will be writing integer, float and strings. So now I am going to execute this code. So code is executed successfully. Now I have to check bin folder whether dammo.txt is created and it is having a as value or not. So I have opened dammo.txt. You can see it is having a as input. Now I am going to write different values in file with the help of f printf. So here you can see I am writing integer that is 22 into this file. So this way with the help of f printf 22 will be stored in file as integer. Again I am calling f printf. This time I am going to write float value. So here format specifier is %f and value is 5.11 and I am writing f so that it can become float value. By default any real number is considered as double and then f printf fp %f and inside double quotes I am writing my name Sanjay. So here writing string into file. So this way I have implemented or I have called f printf four times. First is writing character, second is writing integer, third is writing float and fourth is writing string into a file. Now with the help of printf I am going to display the message data is stored into file. So this message will be displayed on output screen. Now I am going to execute this code and then I will be checking demo.txt whether it is containing the contained or not. So I have executed the program. You can see the output data is stored into file. Now I am moving to build folder and here I will check whether demo.txt is containing these values or not. So you see all four data values are available here for a character value 22 integer, 5.11 float and Sanjay as string. So this way I have called f printf four times to write different kind of values into a file. So I hope you have understood how we can store different kind of values into a file with the help of f printf function in file handling in C programming. If you want to watch more programming related videos you can search my name in youtube. My channel will be available there. You can watch various programming related videos here. Thank you for watching this video.