The Function change_one_line()
change_one_line() receives three parameters: line, oldstr, and newstr. It will replace each occurrence of oldstr in line by newstr. This is the most complicated of the functions. Good that we isolated it. Modular top-down programming.
The pseudocode follows:
receives line, oldstr, and newstr as parameters
while oldstr occurs in line
replace oldstr by newstr
Note:
• pos = line.find(old,pos+newstr.length());
don’t want to find oldstring again if oldstring is part of newstring e.g cause and because. Would create infinite loop.
Post A Comment:
0 comments: