Hey, this one is agaain from File-handling
How do you replace a word in a file with another word.
The algorithm should be somewhat like this
1)Read (fgets) the entire line into a buffer. Locate the word/ position of the word.
2)From that point onwards, OVERWRITE the contents in the buffer with the NEW WORD.
3)Put (fprintf) the modified buffer back into the file.
Fine BUT, doesnt this just shout out that, it'll work only if the word-to-be-replaced and the new-word are of the same length. Otherwise,(assuming the new word is higher in length) to accommodate the new word, it'll over-write over a part of the file which is actually necessary.
Sample Output of error case
File contents : goodsite
Replace good with great
File contents : greatite - WRONG
Expected correct output :greatsite
Please give me your valuable suggestions