Hey guys,
I'm trying to write a program that detects certain things in a file and replaces them. To do this I have created a function to iterate through the file line by line. Also, I have a function that replaces the text with whatever is necessary. However, it doesn't seem to work. Can someone please tell me what's wrong with my program and how to fix it?
There are some basic approaches you could take to achieve what you want:
1. Read the entire contents of the file into memory, manipulate the data in memory and when done write the altered contents back out to the file overwriting the old contents.
2. Read a chunk of data (usually a line if it is a text file), manipulate that data and write out to a temporary file. Repeat until the entire file is read/changed. Delete the old file and rename the temp file to the old name.