+ 1

How to replace a word in text file in c?

The user inputs a word, compiler should search for that word in the text file & replace it by other word and should save it. How to do this without using another file or copying contents to other file?

29th Apr 2019, 7:25 AM
DHANYAMBIKA B
DHANYAMBIKA B - avatar
4 Respuestas
+ 1
Why do you want to do this with out copying to another file? If the words are the same length then this is relatively easy. If they are different lengths then you would have to move a lot of the text around the words; which means rewriting most of the file.
29th Apr 2019, 9:32 AM
Jared Bird
Jared Bird - avatar
+ 1
If its just one word you should be able to do it in linear time. If you need to do multiple words you could use a hash table to maintain linear time. The hash table would mean you need linear space instead of constant. If you do multiple words on the file in place it would be slower but should be the same time complexity, though there would be more ways you could have a less than optimal solution.
29th Apr 2019, 10:09 AM
Jared Bird
Jared Bird - avatar
0
What about time complexity & space complexity sir? I was just trying to do things differently. But failed in doing so. So just curious about the possibilities.
29th Apr 2019, 9:49 AM
DHANYAMBIKA B
DHANYAMBIKA B - avatar
0
Thank you for the information sir, I think i need to work on it more...
29th Apr 2019, 10:16 AM
DHANYAMBIKA B
DHANYAMBIKA B - avatar