title: Remove characters from a string in C
body: <p>I only have access to 'C' and need to replace characters within a character array.  I have not come up with any clean solutions for this relatively simple procedure.</p>
  
  <p>I am passed a character array, for example:</p>
  
  <pre><code>char strBuffer[] = "/html/scorm12/course/course_index.jsp?user_id=100000232&amp;amp;course_id=100000879&amp;amp;course_prefix=ACQ&amp;amp;version=2&amp;amp;scorm_version=3&amp;amp;roster_id=100011365&amp;amp;course_name=Test%20Course%201.2&amp;amp;mode=browse&amp;amp;course_number=0000&amp;amp;mode_id=1";
  </code></pre>
  
  <p>I need to modify this buffer to replace all the <code>&amp;amp;</code> with <code>&amp;</code>.  The resulting buffer does not have to overwrite strBuffer (a new buffer can be created).</p>
  
  <p>Any suggestions?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>In the past I have done the strstr function in a loop, but was looking for a simpler solution, perhaps the C equivalent to the String.Replace method.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>For my immediate needs, the following is all that I need.</p>
  
  <pre><code>char strBuffer[] = "/html/scorm12/course/course_index.jsp?user_id=100000232&amp;amp;course_id=100000879&amp;amp;course_prefix=ACQ&amp;amp;version=2&amp;amp;scorm_version=3&amp;amp;roster_id=100011365&amp;amp;course_name=Test%20Course%201.2&amp;amp;mode=browse&amp;amp;course_number=0000&amp;amp;mode_id=1";
  char strTemp[1024];
  char *s = (char*)strBuffer;
  int i=0;
  
  while (*s)
  {
      strTemp[i++] = *s;
      if (strncmp(s,"&amp;amp;",5) == 0)
      {
          s += 5;
      }
      else
          s++;
  }
  strTemp[i] = 0;
  </code></pre>
  
  <p>Future modifications:</p>
  
  <ul>
  <li>Create a utility function to store this function.</li>
  <li>Pass the search string as a parameter.</li>
  <li>Determine the search string's length, so the hardcoded 5's can be removed.</li>
  <li>Dynamically allocate the strTemp variable.</li>
  <li>Error checking for empty strings and chars not found.</li>
  </ul>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I created a blog post to detail the steps and provide a more flexible solution:</p>
  
  <p><a href="http://www.solutionmaniacs.com/blog/2012/11/25/c-removereplace-characters-in-a-string.html" rel="nofollow noreferrer">http://www.solutionmaniacs.com/blog/2012/11/25/c-removereplace-characters-in-a-string.html</a></p>