title: Copying part of a character array to another array in C
body: <p>So I've been trying to solve the following problem to no avail:</p>
  <blockquote>
  <p>Write a function called removeString to remove a specified number of characters from a character string. The function should take three arguments: the source string, the starting index number in the source string, and the number of characters to remove. So, if the array text contains the string &quot;the wrong son&quot;, the call</p>
  <p>removeString (text, 4, 6);</p>
  <p>has the effect of removing the characters &quot;wrong &quot; (the word &quot;wrong&quot; plus the space that follows) from the array text. The resulting string inside text is then &quot;the son&quot;.</p>
  </blockquote>
  <p>I've tried looking up other solutions but all of them use the <code>memcpy</code> function which I'd like to avoid as it hasn't been introduced in my book yet and I'd rather not &quot;cheat the system&quot; so to speak.</p>
  <p>My removeString function is as follows:</p>
  <pre><code>void removeString (char text[], int x, int y)
  {
      char output[81];
      int i, z = 0;
          
      for ( i = 0; (i &lt;= 81); i++) {
              
          if (z &lt; (x-1) || z &gt; (x+y-1) ) {
              output[z] = text[z];
              //printf(&quot;%i\n&quot;, z);
              z++;
          } else {
              z++;
          }
              
      }
          
  }
  
  int main(void)
  {
      char s1[81] = &quot;the wrong son&quot;;
      int startPoint = 4, runLength = 6;
      
      removeString(s1, startPoint, runLength);
      
      printf(&quot;The new text is as follows:\n&quot;);
      printf(&quot;%s\n&quot;, s1);
      
      return 0;
  }
  </code></pre>
  <p>When I print out the value of &quot;z&quot; I see that it's skipping numbers, but for some reason it looks like its copying all of <code>text[]</code> into <code>output[]</code>.</p>