title: Problem trying to copy portion of a string in C
body: <p>I'm trying to copy from a string up to the first \n. I can't use strtok for this, as I need strtok for something else and it would overwrite it's state.</p>
  
  <p>This is the string:</p>
  
  <pre><code>char fileCopy[] = "HELLO: LD X'0A\nJMP HELLO\n";
  </code></pre>
  
  <p>Here is the code I wrote, with debug prints:</p>
  
  <pre><code>char currLine [255] = {0};
  int i = -1;
  while (fileCopy[++i] != '\n')
  {
      currLine[i] = fileCopy[i];
      printf("%i %c -&gt; %c\n", i, fileCopy[i], currLine[i]);
  }
  currLine[i] = '\0';
  i++;
  printf("%s\n", currLine);
  </code></pre>
  
  <p>When I run it, it prints this for some reason:</p>
  
  <pre><code>0  -&gt; 
  1  -&gt;
  2  -&gt;
  3  -&gt;
  4 ♦ -&gt; ♦
  5  -&gt;
  6  -&gt; 
  7  -&gt;
  8 D -&gt; D
  9   -&gt;
  10 X -&gt; X
  11 ' -&gt; '
  12 0 -&gt; 0
  13 A -&gt; A
  </code></pre>
  
  <p>Which is obviously not the right characters, and the last print statement hangs and never prints.
  If I instead use this for the last print statement:</p>
  
  <pre><code>printf("%s\n", *currLine);
  </code></pre>
  
  <p>It prints "(null)".</p>
  
  <p>What am I doing wrong here?</p>