 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can use fgetters 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 implement solution of this problem. So first I am going to include a header file that is stdli.h, another header file that is stdlib.h. Now I am going to define main function. Inside main function, first I have to declare a file pointer. Now I am going to declare a character adding whose size is 50. Now after these variable declarations, I have to open the file. So for that purpose, I am writing fopen function. Name of file from where I have to read text is line.pxt and I am going to open it in read mode. Now I have to check whether this file is available or not. So for that purpose, I am applying this if condition, which is checking fpw equals to null. So if fp is equal to null, it means file is not open successfully. Then I have to print an error message that is cannot open file. And I am calling exit function so that termination of program can be done. If file pointer is not containing null, then the statements which are available after this if statement will be executed. So in this case, line.pxt must be available in the computer system. Now I have to read text from file using fgetters. So I am calling fgetters. It receives three arguments. First is str in which input will be received. Second is number of characters that we want to read. And third one is file pointer from where text or characters will be received. So here fgetters will be receiving 10 characters. Those characters will be stored inside str and characters will be received through this file pointer. That is fp and fp is pointing to line.txt. So from line.txt file, beginning 10 characters will be stored inside str. Now to show this these contains on output screen, I have called printf function, which will display file contains equals to percent s and this percent s will be replaced with str. So the received content that is available in str through fgetters will be displayed on output screen through printf. Now I am calling f close fp and then return 0. So this way I have implemented the use of fgetters function, which is reading text from file. Now see this program test.c. This is the name of file is saved in CTCN bin folder. So I have to check whether line.txt is available in this path or not. So I am opening bin folder and here you can see line.txt is already available. I have created this notepad file. I am opening this file. You can see it is containing India is my country and I love India. So this content is available in this file. Now I have to execute the program so that I can demonstrate you the use of fgetters, whether it is working properly or not. So while I will be executing this code, I don't have to enter anything. fgetters will automatically read content from file and that content will be displayed automatically on output screen. So you can see the output. It is showing India is so I and D I A 5 then space 6 then I 7 then as 8 then space 9 after is there is a space. So it is receiving nine characters successfully and on 10th position null is stored automatically. So if if you want to read a total 10 characters, then you have to pass 11 here. Right now I have passed 10 so it is reading total 9 characters. Now you can see the file again here I and D I A 5 characters then 6th space 7 8 9. So before my there's a space. So till that space, all the characters are displaying on output screen. Now if you want to read more characters then you have to increase the second argument of fgetters. Say I'm typing here 20. So this time it will read 20 characters 19 characters and one null character. So now again I'm executing this code. You can see it is showing India is my country. So right now it is reading nine characters from file and on 20th location null is available. So this way I have demonstrated you how you can use fgetters function to read number of characters from file. Here you have to pass how many how many characters you want to read. So I've got this receives three arguments. First one is string in which data will be received. Second argument is number of characters that you want to read. And third argument is the five pointer from where you want to read the characters. So I hope you have understood how we can use fgetters function in file handling in C programming. If you want to watch more programming related videos, you can search my YouTube channel by typing my name Sanjay Gupta in YouTube. My channel will be available there. You can watch various programming related videos there. You can also download my Android app Takimins which is available on Google Play. Thank you for watching this video.