 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can use fgetc function in file handling 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 fgetc. First of all, I am going to include two header files. First one is std.h and second one is stdlib.h. Now I am going to define main function. Inside main function, I am declaring a file pointer that is fp. Then I am declaring a character variable that is ch. After declaration of this character variable, I am going to open the file using fopen function. So in fopen function, I have to pass the name of file which I want to open. So I am passing name of file contained.txt and I am going to open this file in read mode. So fgetc is a function which can read a character from file. So I am going to read the contents which are available in this file that is contained.txt. That's why I have opened it in read mode. Now I have to check whether this file is available or not. So for that purpose, I have implemented if condition fpw equals to null. So if file pointer is containing null, it means contained.txt is not available. Otherwise it will be available. So if fp is equals to null, then I have to show a message on output screen. Error cannot open file and then I have to terminate execution of the program. So exit function terminates execution of the program. So till now I have opened a file. I have checked whether it is successfully opened or not. Now I have to read the contents which are present in contained.txt file. So I am going to implement a while loop. This while loop is infinite loop because its condition is one and one is always true. Now inside this loop, I am going to call fgetc like this. So I am using fgetc. I have passed file pointer fp. So fgetc will read a character from this file pointer and the character will be stored inside ch. Now I have to check whether this ch is equals to EOF or not. EOF means end of file. So in every file at the end, EOF value is available. So if ch is equals to EOF, then I have to break this loop because after receiving EOF value, no characters are present in a particular file. So I can break the loop. If this condition ch equals to EOF is false, it means character is not equals to end of file. Then I can print that character on output screen using printf. So here you can see through fgetc, I am reading a character from file. Then I am checking whether it is equals to EOF or not. And then that character will be displayed on output screen with the help of printf function. So this way I have implemented this loop to read the contents of file and those contents will be displayed on output screen. After this, I can call fclose fp and then return 0. So this way I have implemented the complete program in front of you, which is demonstrating you the use of fgetc, which is responsible for reading a character from file. Now before execution of this program, I have to check whether this contain.txt is available or not. So I am going to check it through this program. So I am executing this. You can see it is showing an error message cannot open file. It means contain.txt file is not available right now. And the source folder is stored in C drive, tc folder and bin folder. So in this path, I have to create this contain.txt file so that this file can be linked with this test.c program. So I am moving to C drive, tc and bin folder. Here I have to create a file. So I am opening notepad. I am typing some text in this. My name is Sanjay Gupta. Now I am going to save this file. So you can see I have selected path C drive, then tc folder and then bin. Here I have to save this file with contain.txt. So I have successfully created this file. Now file is available in bin folder that is contain.txt and it is containing the text. My name is Sanjay Gupta. Now again I am going to execute the program. You can see the output. It is showing the content which is available in the contain.txt file. That is my name is Sanjay Gupta. So this way I hope you have understood how we can read all the characters which are available in the file using fgetc. If you want to watch more programming related videos, you can type my name in YouTube search that is Sanjay Gupta. My channel will be available there. You can watch various programming related videos there. You can also download my android app Techimus. Thank you for watching this video.