 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can read an integer from a file 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. My channel will be available there. You can watch various programming related videos there. Now I am going to demonstrate you how you can read an integer from a file in C programming. So, first I am going to include a header file S, sorry, S-T-D-I-O dot H. Now another header file is S-T-D-L-I-V dot H. Now I am going to implement main function. Inside main, I am going to declare a variable int n. Then another variable is a pointer whose data type is file. So this is file pointer which will receive an address of a file from where I am going to read an integer. So now I am going to open that file through fopen function. So I am passing name of file as number dot txt and I am going to open it in read mode. So if I am going to open a file in read mode, then it must be present in the computer's hard disk. So for that purpose, I am applying this condition to check whether the file is available or not. So if file pointer is receiving null, then file is not available. If file pointer is not receiving null, it means file pointer is having an address and that address belongs to this file that is number dot txt. So if file pointer is equal to null, I can print the message on output screen. Error cannot open file. And then it will show, sorry, and then it will call exit function. Exit will terminate execution of the program. Now I am going to read the number from number dot txt. So for that purpose, I have to call the function fscanf. Then I am going to pass file pointer. Then inside double quotes, I am writing %d and then %n. So the number will be stored inside n variable. Its type will be integer because I am using %d and source will be fp pointer. So from fp pointer, number will be stored inside n variable. Now through printf, I can print the message number equals to %d on output screen. So number will be stored inside n variable through fscanf. So reading operation will be done with the help of file. And output will be displayed on output screen with the help of this printf. So while executing this program, user doesn't have to enter any value. It will show output on output screen. So input will be received from file only. So this way I have implemented this complete code. I can also call fclosefp so that I can close the file. So I have implemented complete code in front of you. Now I am going to execute this code. So you can see the output. It is showing error message cannot open file. Why so? Because I have not created number.txt. So if file is not available, this r-mode doesn't open that file. A file must be available if you are using r-mode. So now first I have to create number.txt file. Then only I can execute this program successfully. So for that purpose, I have to open c drive first, then tc folder and then bin folder. Inside bin folder, I have to create a notepad file. Name of that file must be number.txt because I have used that name only. So for that purpose, I am opening notepad. Inside notepad, I am typing a number that is 10. Now I am going to save this file in c drive, then tc folder, then bin folder. Here I am going to save this file as number.txt. So now you can see in bin folder, this file is available. That is number.txt. Now again, I am going to execute this code. You can see the output. It is showing number equals to 10. So this time number.txt file is available in our computer system or computer's hard disk. So this program is reading number.txt file successfully through this r-mode. So remember that whenever you are using r-mode, it means the mentioned file must be available in your computer's hard disk. Then only the program will be executed perfectly. Otherwise, the program will show the error message as this program showed earlier. So I hope you have understood how we can read an integer from a file in c programming. If you want to watch more programming related videos, you can search my name Sanjay Gupta in YouTube. My channel will be available there. You can watch various programming related videos there. Thank you for watching this video.