 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can count number of characters that are present in a file using C program. 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 here. Now I am going to implement a C program. First of all, I am going to include two header files, stdio.h and second one is stdlib.h. Now I am going to define main function. Inside main, I am going to declare a file pointer that is fp, then a character variable ch and integer variable count, which I am going to initialize with 0. Now through f open, I am going to open a particular file whose characters I want to count. So I am typing name of file as data1.txt and I am going to open this file in read mode. So I am applying if condition fp double equals to null. This condition will check whether file pointer is received a particular address of a file or it is containing null. If it is containing null, it means file is not opened successfully. So I can print error message that is cannot open file. And I can terminate execution of the program by calling exit function. So this way I have opened data1.txt file pointer fp. I have checked whether file pointer is containing a particular address or null. After this checking, I have to read characters that are available in a file and I have to count how many characters are available in that file. So for that purpose, I am applying an infinite loop. That is while 1. Now inside this loop through fgetc, I am going to read a particular character available in a file. So fgetc will read a character from fp file pointer and that 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. Each file contains eof at the end of its contents. If end of file is available, it means files contents are finished. So if ch is containing end of file, it means no more characters are available in a file. So I can break the loop. Otherwise, I have to count variable count by incrementing it 1. So now you can see this complete loop. fgetc is reading a character. Then if condition is checking whether it is equals to eof or not and count is incrementing its value by 1, every time loop will be executed. So suppose this loop executes 10 times. It means 10 characters are available in the particular file. So value of count will be 10. And whenever end of file will be occurred in ch, then only this loop will be terminated. Now after completion of this loop, I can close the file and I can print counted characters on output screen with the help of count variable. And then I am writing return 0. So this way I have implemented the complete code in front of you. Now I have to make sure that data1.txt must be available in the system. And the path will be ctcbin because test.c that is the source code which I have written in front of you. It is stored in test.c and it is stored in ctcbin. So I am opening bin folder. The location is ctcbin. Here data1.txt is already available. I am opening it and it is containing sanjay. That is my name. I am closing it. Now I am going to execute this program. You can see the output. It is showing counted characters equals to 6. So I have already demonstrated you the data1.txt that is containing sanjay and it contains 6 characters. Now I am going to show you if we mention another file name, what will happen. So here another text file is available that is contain.txt and here my name is sanjaygupta is written. So now I am going to change name of this file and I am writing contain.txt. So this time this program will be opening contain.txt and it will be counting how many characters are available in this file. So again I am executing this code. You can see it is showing counted characters equals to 24. It means contain.txt is containing 24 characters. And you can count these characters. If you count these characters including spaces and dot these characters will be 24. So this way I have demonstrated you how you can count number of characters that are available in a particular file with help of C program. I hope you have understood this logic well. If you want to watch more programming related videos you can search my name sanjaygupta in YouTube. My channel will be available there. You can watch various programming related videos here. You can also download my programming app Takimiz. Thank you for watching this video.