title: Stack Smashing Detected in C
body: <p>I have a loop running to add spaces between some special characters (&amp;,|,&lt;,>). The following code successfully adds spaces before and after a special character:</p>
  
  <pre><code>    char keys[] = "&lt;&gt;&amp;|";
      int i = strcspn (input,keys); 
      appenda(input, " " , i);
      appenda(input, " " , i+2);
  </code></pre>
  
  <p>The above code converts input "asdf&amp;asdf" to "asdf &amp; asdf".</p>
  
  <p>However, my goal is to do that for every special character in the entire input even with multiple special characters (like "asdf&amp;asdf&amp;asdf"). So I made a while loop:</p>
  
  <pre><code>    char keys[] = "&lt;&gt;&amp;|";
      int i = strcspn (input,keys);
      while(i &lt; strlen(input)){
          appenda(input, " " , i);
          appenda(input, " " , i+2);
          i = strcspn (input,keys);
      }
  </code></pre>
  
  <p>Yet, when I run my code now, it returns with "<strong><em>*</em>**</strong> stack smashing detected <strong><em>*</em>**</strong>"</p>
  
  <p>Any Ideas on what this means and how to get around it?</p>
  
  <p><strong>EDIT</strong>
  Appenda inserts a string into another string at a designated point. it takes in 3 arguments: 1st is a string which i insert into, 2nd is a string which i want to insert and 3rd is the index. so appenda(ABCD, X, 2) returns AXBCD       </p>