title: Copying one part of a string to another in C
body: <p>I have problems trying to copy one part of a string into a another. Given these two char pointers:</p>
  
  <pre><code>line points at string cointaining: "helmutDownforce:1234:44:yes"
  username points at: NULL
  </code></pre>
  
  <p>Here's my function that takes these pointers as input:</p>
  
  <pre><code>char* findUsername(char* line, char* username){
      char* ptr = strstr(line, ":");
      ptrdiff_t index = ptr - line;
      strncpy(username, line, index);
  
      return username;
  }
  </code></pre>
  
  <p>I get segmentation fault during strncpy. How come? The result I want is the function to return a pointer to a string containing helmutDownforce.</p>