Hi guys.
Welcome back.
OK.
In this session we will write a simple program in order to open a file.
Read the content of the file and display in the second set.
I already have a final here.
So my program also resides in the same path.
So I have created a file on desktop.
OK so in this I just mentioned welcome to take what I've got.
I mean it can be anything actually.
So the object of this program is to or the program should be able to open this fine and read this content.
And this fantasy concept.
OK so that's it.
OK.
So now we will go line by line.
OK.
So this is the header file as I mentioned my illustration.
We are using the central front to enroll in some of the Will functions.
And there's a main function that program while distance from the main function.
And this integration by parts of the file point up.
So this this this declaration and this statement are mandatory.
So here I have declared this a pointer to the file on that.
After this though what happens is the address of the first character is stored in the file by roughly
FBI.
Okay then again I'm using this FP one in order to open the file in read format.
As I mentioned earlier Timothy decision what are what you want to do it actually for example before
and open the file in the read format or right format or output format.
You have to specify here program he had in this program.
I have given just a filing here because the program and the text file remains the same but so no need
to specify any part or here.
Okay.
So now.
So I have done with the declaration I already opened a file in great format and I'm using this character
variable because down the line I'm going to use this variable.
Okay.
So once I read this once they open this file format it could be a possibility that it's not able to
open the file.
So that's why there is one module unconditional here.
Yes this particular file if it's not able to open it written and not okay so it will give a message
not able to open this file Christian.
Okay.
Which means the C program would if I'd open this file in read format if it's able to open successfully
then it'll come to this endless loop.
Otherwise it will fail or here itself it to come to this loop and it'll print this message and it'll
come out of this law.
Okay.
So if if there is no error it's impossible to open the file successfully which means at that time it
will give him a C the final has been opened successfully of the body will come to this right.
Okay.
So what I'm doing here is I mentioned is one only because I want to get into this law because if it
is not in case of C through means 1 5 0 if it is one get into this look for a zero interest conditional.
Okay.
So I mentioned is one.
So each suite can get into this look.
So um what I'm doing is with the help of this C function and reading the content I know I'm reading
the character from the file.
Okay see here what I mentioned is if we want to just opened this file and read format after that and
reading the content and storing here.
Okay so one by one one by one.
So what happens is there is one which I call here is EGF in our program to determine the end of the
file.
So once is and then we'll put a break and we'll be put any big statement yes.
I feel wanted which is yet to come out of this room.
Otherwise it'd be good to keep on printing it whether it is a b c to whatever it is it may be keep on
printing in the second so.
Okay.
So after this we have a f growth function as I mentioned material section there'll be three steps open
perform your operations and close your file okay.
Is it dangerous for the normal termination again I'm repeating this function this 5.0 the clinicians
mandatory.
So we are used if we want and after that we are just opening the file and read format object you have
the C.
This program is open to find an excellent amount whatever the content is available in the file.
I mean in this particular site it should read it and it should display in the sequencer.
OK.
So after opening it I'm just checking whether I'm able to open successfully or not.
That's why I mentioned that I mentioned this.
I put this check if Bill 1 is called Not if it is not admins it can.
It's not able to open the file so I open this message was able to open the file I'll get this message.
The file has been opened successfully then I have a way.
Look I mentioned once or the control come inside say I'm just reading the file contained character by
character and I'm storing it here if if I'm able to if I have reached the end of the file I love a break
and it'll come out of this loop it will keep on printing you know in this sequence.
Okay so after that I once is done it will come off of this loop and after that I'm using f closed function
to close a file and return 0 signatures in number.
Okay.
Now we will execute this program and see what happens.
Okay.
So I'm just saying this
okay.
So now if you see here this mentioned the file has been opened successfully which means that this message
has been printed successfully now for that.
Welcome to Ecuador Academy.
Okay.
So let me open my file is my file.
So what I have mentioned here is pretty successful.
Okay.
Now let's change this contact.
Thanks for watching this media.
Okay video session.
Okay.
So now let us execute one more time and see whether we are able to be able to whether the program can
read the content.
So I'm saving it to be Miss Burlingame okay.
See so now again is printing the file has been opened successfully.
Thanks for watching this discussion so much.
Okay so now what we can do is like Oh we've all been in this fight okay in this fight.
So no you should throw an error right because it's trying to open in a format.
If it's not able to find a fight it will be intentional.
So after that like this message should be printed.
So let's see what happens now.
See inaudible to open the fight which means here it is text or the XY the same part.
There is no study of G so it failed and it didn't actually return not up as it did not.
This uh this condition became true and this message has been printed.
But we will do one more testing by keeping the program under file in a different location now.
So now if you see here my program is in dislocation my that's fine.
I assume that it is the stool is in a different location.
OK.
So now my objective here is to read this content and it's going to see counsel it was a different part.
You have to give that bottle here.
OK.
So I'm giving him the final name is still right there stored on the extra OK.
It's not when you're mentioning the part here.
It should be in double slash.
OK.
So now what is written here it is.
Welcome to Michael Gordon.
So when you go on this program you should printable come to my tutorial.
I'm just building it and running it again.
Thank you.
Welcome to my tutorial
welcome to my devoted change handle for example.
I'm just changing the content again.
Again I'm just reading it.
I'm running it.
It's printed successfully.
Hello it also it's hello.
OK so this is how we can write a program in order to read the content of a fried existing file and this
being the second zone even if the file is resides in the same location where the program is on a different
location.
OK.
So thanks for watching this session.
I'll catch you guys in the next video.
My final.