title: Copying part of a string in C
body: <p>This seems like it should be really simple, but for some reason, I'm not getting it to work. I have a string called seq, which looks like this:</p>
  
  <pre><code>ala
  ile
  val
  </code></pre>
  
  <p>I want to take the first 3 characters and copy them into a different string. I use the command:</p>
  
  <pre><code>memcpy(fileName, seq, 3 * sizeof(char));
  </code></pre>
  
  <p>That should make <code>fileName = "ala"</code>, right? But for some reason, I get <code>fileName = "ala9"</code>. I'm currently working around it by just saying <code>fileName[4] = '\0'</code>, but was wondering why I'm getting that 9.</p>
  
  <p>Note:
  After changing seq to </p>
  
  <pre><code>ala
  ile
  val
  ser
  </code></pre>
  
  <p>and rerunning the same code, fileName becomes <code>"alaK"</code>. Not 9 anymore, but still an erroneous character.</p>