-1

Im trying to read a file not just from the last line but from the end of the line to the beginning too. Example:

Im trying 
to read a file

How do I want to read:

elif a daer to
gniyrt mI

How do I do that?

  • You can do it with a *lot* of seeking. Or if the file is small enough. reading it all into memory and start from the end of the data. Or by reading into memory and reverse the in-memory copy. Or by memory mapping the file and start from the end of the mapped data. There are probably more ways, but at least it's a start for you. – Some programmer dude Apr 13 '17 at 16:44
  • This is a classical XY-problem. Read the file as is and then reverse. – Eugene Sh. Apr 13 '17 at 16:44

1 Answers1

0

You read each line, put all in a buffer ..reverse it and then parse. The thing is most of the time it is not needed to read the file in reversed manner..But you can try this.

Some nice organized manner of doing this will be..using a LIFO data structure. You can use a simple array and make it behave like a stack. Push everything then pop from top.

user2736738
  • 30,591
  • 5
  • 42
  • 56