How can I read a file backwards and copy it?
Example:
file 1:
a
b
c
file 2:
c
b
a
Read a File Backwards
Started by Paradine, Dec 23 2006 01:47 PM
4 replies to this topic
#1
Posted 23 December 2006 - 01:47 PM
|
|
|
#2
Posted 23 December 2006 - 03:37 PM
You could copy the file contents to a buffer then output them to another file backwards at your leisure?
Or, (assuming you're using C) you could look into the lseek() function which repositions the file offset - start at the end of the file, read a character, decrement the offset with lseek, repeat; then ouput the buffer to a new file?
I'm just a newbie, but those are my suggestions.
Or, (assuming you're using C) you could look into the lseek() function which repositions the file offset - start at the end of the file, read a character, decrement the offset with lseek, repeat; then ouput the buffer to a new file?
I'm just a newbie, but those are my suggestions.
May the source be with you... always
#3
Guest_Jordan_*
Posted 23 December 2006 - 04:01 PM
Guest_Jordan_*
I agree. If you are splitting the file by line breaks (which it looks like you are) you can just read the array backwards as you write.
#4
Posted 26 December 2006 - 08:13 AM
You could always byte read it backwards.
#5
Posted 29 December 2006 - 09:55 AM
For C++, you could create a stack of strings, push strings on the stack as you read, then pop them to write the output.
What size files are you looking at working with?
What size files are you looking at working with?


Sign In
Create Account


Back to top









