 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can use fscanf 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 fscanf. So fscanf is a predefined function which can read any kind of value from a file. It can be integer, float, character or string. So for demonstration purpose, I am going to include a header file stdir.h. Another header file that is stdlib.h. Now I am going to define main function. Inside main, I am declaring a file pointer that is fp. Then an integer variable n, character variable ch, float variable f, and character array that is str. So these four different variables will be receiving four different values from a file. So first I am going to open a file whose name is tamo.txt and I am going to open it in read mode. After calling f open, I have to check whether the file is open successfully or not. So I am writing this if statement. It will check file pointer will be having null or not. So if file pointer is containing null, it means file is not open successfully. So I can print the message error cannot open file and I can call exit function. Now after checking this if condition, if this condition is false, it means file pointer is containing an address. I can call fscanner function to read values. So first I am going to open damo.txt so that you can check what content it is having. And this damo.txt file is available in ctcnbin folder. Why so? Because this source code is stored in test.c file and test.c file is stored in bin folder that is available in c drive. So right now I am opening bin folder which is available in tc folder and tc is available in c drive. So here you can see damo.txt file is available and it is having a 22 5.11 0 0 0 and Sanjay. So first is character value second is integer third is load and fourth one is string. Now I have to read all these contents with help of fscanner. So I am going to write fscanner. So it is reading characters. So fscanner is reading character from file and that character value will be stored inside ch variable. Again I am going to call fscanner. This time it will read integer and that integer will be stored inside n variable. Here you have to follow the sequence in which sequence values are stored in file. You have to follow that sequence here. Otherwise input will be converted into garbage values automatically. This will read float values string. So all the received values will be stored inside ch and f and str. Now I have to show these variables on output screen. So for that purpose I am calling printf. So ch equals to percent c then printf n equals to percent d then printf f equals to percent f and printf str equals to percent s. So this way all the received values will be displayed on output screen. So while I will be executing this code I don't have to enter anything. The data will be received from file automatically and that received data will be displayed on output screen automatically. So at last I am calling fclose fp and then return 0. So this way I have implemented complete code in front of you which will read four different type of values from file and that values will be displayed on output screen automatically. So now I am going to execute this code. You can see the output ch equals to a n equals to 22 f equals to 5.11000 and str equals to sunday and these details are available in demo.txt. So you can compare both the values which are available in file are automatically displayed on output screen. I have not entered anything from this console. The program has received input from file and it is displayed on output screen. So I hope you have understood how we can read different type of values from file with help of fscanf. If you want to watch more programming related videos you can search my name Sajag Gupta in YouTube. My channel will be available there. You can watch various programming related videos here. Thank you for watching this video.