I have a large file and I need to get only the last line from it (\n
only is the line separator).
I need this to be done on iOS device, so it cannot take much memory or cpu time (like reading the whole file).
How can I do this in either Objective-C,c++ or c++11?
Conceptually I think you'd want to open the file and seek the whole way to the end minus N bytes (maybe 80 or something). Then read that and look for the \n. If you don't find it, then seek N bytes earlier and try it on that set of N bytes, and so on until you find the \n.
As for the specific calls, that's just a matter of looking up how to open a file, seek around in it, and read data. Should be pretty straightforward. But I think the above is what you'd want to do and pick a size for N which isn't too large.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With