Hello, in this video, we are going to take a look at reading in a single line. So at the moment, it reads the entire file. And as you can see, it's on separate lines. So this is actually really simple. So instead of F read if we do f gets. So that's how you read a single line, and we don't need to specify the full size for this, we can get rid of that, you still need to open the file still need to close the at the end.
And now if we save that, and run it, we just get a single line. So if you want to get a novice single line, what we would recommend, or I would recommend is if, let's say for this echo decide, it's just easier to demonstrate what I'm going for this should still run the same way. If I duplicate this. That's great. So what it's done, if we need to do one more time And there we go, we've got the next line. So it's put a space there because there would have been a, this part right here.
So that's basically a, you know, an empty space character. And if we wanted to obviously put a break here, we could literally format these ourselves. So we could actually just put something like this. And now if we was to run it, there we go, we get the format that our file was originally in. So that's how you read a single line. And apart from that, and nothing more to it.
What I want you to do is figure out how to basically go through the entire file and read all of the line because one, there may be more than three lines. It may not be practical to do this. too, you may not know how many actual lines out in the fall. So low recommendation, look at using something like a loop which was one of the many control structures that was covered in the control structures part of this series. Feel free to you know, check that out if you haven't already done so or as a little refresher and figure out how to read every single line in the file and print it out in this fashion. Any questions feel free to drop me a message and as usual, I look forward to seeing you in the next video.