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.

Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: