How do I replace a word in a file with another word using C
?
For example, I have a file which contains:
my friend name is sajid
How about using the exiting Linux sed program?
sed -i 's/friend/grandfather/' filename
That will replace friend with grandfather in the existing file. Make a copy first if you want to keep the original!
Edit:
Alternatively, load the file into an STL string, replace 'friend' with 'grandfather' using a technique such as this, and save the new string into a file.