Hello, and welcome back.
In this challenge, I want to help you become familiar with
changing the position of a file.
So what I want you to do is I want you to use the fseek and the ftell
functions to be able to basically change the position so you can
point to the middle of the file as opposed to the beginning or the end.
So you're going to write a program that's going to print the contents
of a file in reverse order.
You're going to use the fseek function to seek to the end of the file.
So you're going to start reading from the end of the file by moving
the position to the end of the file.
You're going to use the ftell function to get the
position of the file pointer.
So fseek is going to move the position but you need to get the
position using ftell to then start doing your writing and reading.
You want to display as output the file in reverse order.
And so these are going to again be some basics here.
You're going to need to create your file beforehand.
Some simple text file that contains whatever you want inside of it.
And then you're going to need to create a file pointer,
and you're going to open up that file and read only.
As you're reading in the file, before you start reading the
file, you can seek to the end of the file using fseek method.
Once you have used the fseek method, you can then use the ftell
method to get the actual position.
You then can use the position to start printing out of
the characters using fgetc.
So we want to get the position of the file pointer and we want to
use that to be able to seek to the end and display some information.
The reason we need to use the ftell is because then our
while loop knows when to exit.
So we want to use ftell for the number of bytes, and we
can increment our counter.
And so we're going to basically go from the beginning to the
end using the counter and then printing it in reverse order.
So these are the functions we're going to use.
There are many different ways to implement.
This just one.
If you have any questions, please email me.
This is going to get you familiar with ftell and the fseek function.
Thank you.