How to use lseek to read the last character of a file

I am trying to read characters from a file in reverse order with lseek.

So far I have had:

 int finished = 1;
 char temp[1];

    while (finished > 0) {

 lseek(fileID,0,2);

 finished = read(fileID, &temp, 1);

 cout << temp[0];

    }

But reading always returns 0.

Any ideas on what to do?

+3
source share
1 answer

Of course, calling lseek () should be

lseek(fileID, -1, SEEK_END);

You are looking for the end of the file and you need to be one byte.

+7
source

Source: https://habr.com/ru/post/1786320/


All Articles