0

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);
    }
}
lp1172
  • 1
  • 2
  • 3
    possible duplicate of [C - Replacing words](http://stackoverflow.com/questions/26186734/c-replacing-words) – Ken White Feb 18 '15 at 02:37
  • possible duplicate of http://stackoverflow.com/questions/28574583/c-program-copy-text-from-stdin-to-stdout/28574709#28574709 C program - copy text from stdin to stdout. Did this homework assignment just get posted or something? – jschultz410 Feb 18 '15 at 02:45

0 Answers0