Reputation: 6675
A good example of what I'm trying to do could be seen in one of the following 2 samples:
read from a file char by char, at the start of a new line, prefix a line number (or something) manipulating the original file.
read from a file char by char, converting upper to lower, or lower to upper, manipulating the original file.
Only reason I ask is I've only ever done this by reading or writing a stream, not both operations on the same file (and never backtracking)
Also it seems I have 2 modes to operate in, insertion, and replacement. Any guidance would help, documentation would be even better. (code samples backing them up would be much loved)
Upvotes: 0
Views: 1020
Reputation: 490058
Converting case in place is pretty trivial:
This, however, only works because you're leaving the data the same length. Adding a line number to each line is a whole different story. To do it "in place", you basically have to read in the whole file, modify it in memory, then write it all back out. If it won't fit in memory, you'll have to modify it as you copy to another file, then copy that back to the first, or something on that order.
Upvotes: 2