title: Why should you use strncpy instead of strcpy?
body: <p><strong>Edit: I've added the source for the example.</strong></p>
  
  <p>I came across <a href="http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/index.jsp?topic=/com.ibm.etools.iseries.langref.doc/rzan5mst269.htm" rel="noreferrer">this example</a>:</p>
  
  <pre><code>char source[MAX] = "123456789";
  char source1[MAX] = "123456789";
  char destination[MAX] = "abcdefg";
  char destination1[MAX] = "abcdefg";
  char *return_string;
  int index = 5;
  
  /* This is how strcpy works */
  printf("destination is originally = '%s'\n", destination);
  return_string = strcpy(destination, source);
  printf("after strcpy, dest becomes '%s'\n\n", destination);
  
  /* This is how strncpy works */
  printf( "destination1 is originally = '%s'\n", destination1 );
  return_string = strncpy( destination1, source1, index );
  printf( "After strncpy, destination1 becomes '%s'\n", destination1 );
  </code></pre>
  
  <p>Which produced this output:</p>
  
  <pre>destination is originally = 'abcdefg'
  After strcpy, destination becomes '123456789'
  
  destination1 is originally = 'abcdefg'
  After strncpy, destination1 becomes '12345fg'
  </pre>
  
  <p>Which makes me wonder why anyone would want this effect. It looks like it would be confusing. This program makes me think you could basically copy over someone's name (eg. Tom Brokaw) with Tom Bro763.  </p>
  
  <p><strong>What are the advantages of using</strong> <code>strncpy()</code> <strong>over</strong> <code>strcpy()</code>?</p>