I am writing a c program that takes a text file and reads through the file searching for a specified word. The program then replaces the word with another chosen word. The problem I have is that using fgets replaces the whole line and not just the chosen word. Any help would be appreciated. Thanks. This is the block of code.
while (fgets(ch, 20, ifp) != NULL){
if (strstr(ch, argv[2]) != 0)
{
fputs(argv[3], ofp);
}
else
{
fputs(ch, ofp);
}
}