A couple of things I've noticed: 1. You are always using 'file1.txt' in your code, not the filename(s) passed as argument 2. As has been pointed out, lines can be longer than 1000 chars. 3. You never close the file you've opened. That will cause changes in one file buffer to overwrite previous changes once the files are closed (or at the end of the program). 4. You only check for one occurence of a word per line. What if there are multiple occurrences? Suggestions: - As already pointed out, start with your replace functions and make sure they work as intended, before dealing with files! - Make sure you always close the files you've opened - Write the modified text into another, temporary file. Later erase the original file, and rename the temporary one. That way you can just keep on reading/writing without needing to close/open the file over and over again.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)