replace - Replacing a word in a file, using C -


how replace word in file word using c?

for example, have file contains:

my friend name sajid 

i want replace word friend grandfather, such file changed to:

my grandfather name sajid  

(i developing on ubuntu linux.)

update:

i doing filing in c. have created .txt file , write data it, program progresses have search text , replace other words. problem facing suppose in file wrote

"i bought apple market" 

if replace apple pineapples apple has 5 char , pineapple has 9 char write as

"i bought pineapple m market" 

it has affected words written after apple.

i have using c, not command line script.

how using exiting linux sed program?

sed -i 's/friend/grandfather/' filename

that replace friend grandfather in existing file. make copy first if want keep original!

edit:

alternatively, load file stl string, replace 'friend' 'grandfather' using technique such this, , save new string file.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -