title: Replacing character in a string
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/779875/what-is-the-function-to-replace-string-in-c">What is the function to replace string in C?</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to replace a certain character in my string with multiple characters. Here is an example of what I am trying to do.</p>
  
  <p>Say I have the string "aaabaa"</p>
  
  <p>I want to replace all occurrences of the character "b" with 5 "c"s. </p>
  
  <p>So when I am done, "aaabaa" becomes "aaacccccaa" </p>
  
  <p>I have written the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  int main(void)
  {
      char s[20] = "aaabaa";
      int i, j;
      for (i=0; s[i]!= '\0'; i++)
      {
          if (s[i] == 'b')
          {
              for (j=0; j&lt;5; j++)
              {
                  s[i+j] = 'c';
              }
          }
      }
      printf("%s\n", s);
  }
  </code></pre>
  
  <p>My output from this function is "aaaccccc". It appears that it just overwrites the last two a's with the c's. Is there any way I would have it so that these last couple of a's dont get overwritten?</p>