title: Replace all occurrences of one string with another in a stream of text
body: <p>As the title says, how do I replace a string with another string? For example: the user would enter three inputs. The first input is the string that the program would replace; the second is the string that would replace input1; and the third is the string that would be printed out. So if:</p>
  
  <p>Input1 = peanut</p>
  
  <p>Input2 = coconut</p>
  
  <p>Input3 = replace<strong>peanut</strong>replace</p>
  
  <p>Output: replace<strong>coconut</strong>replace</p>
  
  <p>I have started it but my program can only replace words with the same length. I tried searching my problem, but I do not understand the given solutions since I am just new at C/C++.</p>
  
  <pre><code>char replacing[100];
  char replacement[100];
  char original[1000];
  int count;
  
  cin &gt;&gt; replacing;
  cin &gt;&gt; replacement;
  
  while(! cin.eof())
  {
      cin &gt;&gt; original;
  
      char * pch;
  
  
      pch = strstr (original, replacing);
  
      count = strlen(replacement);
      strncpy (pch, replacement, count);
  
  
      cout &lt;&lt; original &lt;&lt; endl;
  
  }
  </code></pre>