Open the input file. Open a temporary output file. Read the input file line by line. Process one line of input. Write it out to the output file. When done, append your additional information to the output file. Close the input file. Close the output file. Then rename your temp file so that it replaces your input file. Do your writing in standard ">" mode, because you're writing a new temp file, not appending to an existing file.
This is quite the long-winded approach. Why would you want to have to read and then write back out each line, even ones that are not being modified? Too much file input/output! Take a look at my solution. It simply scans the file once over and appends the data (if necessary) at the very end. Simple yet efficient.
In reply to Re^2: appending to a file
by Anonymous Monk
in thread appending to a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |