Replacing a word into other word

S

sri.mohankumar

hi
i want replace one word to another in a file .i am trying to use in
gets

by
SRI
 
N

Nick Keighley

i want replace one word to another in a file .i am trying to use in
gets

gets() does not read from a file. It is also fatally flawed in its
handling of overflows. *Never* use gets(). Use fgets() to read line.
Use strstr() to find the word. The substitution is trickier.
Consider this line:-

"small elephants hate elephants optics"

To replace "hate" with "love":-
find the "hate"
write the line to another file (use fputs()) until you
reach "hate"
write "love"
write the rest of the line

Give it a try. If you get stuck post what you've written.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top