Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File manipulation

Status
Not open for further replies.

malladisk

Programmer
Jun 14, 2001
69
US
Hi, I have a file. I need to copy its contents in reverse order of lines. I mean, the first line of the source file should be the last in the desination file, the second one should be the last but one and so on.
Thanks,
Sashi
 
Use a stack... push the lines of data into the stack, one line at a time and when you pop em out they will be in revers order.

Second Option is to use

CList<CString,CString> // i think this is also CStringList

Put them into this by using AddTail and when you print em out just traverse it from the head down.

Matt
 
Keeping line contents in the memory may be complicated, if the file is big enough. Try to stack only line start offsets, then extract them using fseek().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top