开发者

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

I'm trying to read the char开发者_如何学Goacters from a file in reverse order using lseek.

So far, I have:

 int finished = 1;
 char temp[1];

    while (finished > 0) {

 lseek(fileID,0,2);

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

 cout << temp[0];

    }

But read always returns 0.

Any ideas on what to do?


Surely the call to lseek() should be

lseek(fileID, -1, SEEK_END);

You are seeking to the end of file and you need to be one byte short.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜