C Program to Read last n characters from the file !

Write a C program to read last n chatacters of the file using appropriate file function

Problem Statement : Write a C Program to read last n characters from the file . Open a file in read mode. Accept value of n .

Output :

Actual Content from File :

Explanation of the Code :

Firstly open file in the read mode.

Now we need to accept position number so that we can start reading from that position. We are moving file pointer to the last location using fseek() function and passing SEEK_END constant.

Now we need to evaluate the current position of the file pointer.

ftell() will tell you the location of file pointer.

We need to read last n characters from the file so we need to move pointer to (length-n) character back on the file. and from that location we need to read file.