title: How to only copy over the first n number of chars from a scanf in C
body: <p>Sorry I'm sure how to word my question properly.</p>
  
  <p>I'm working on an assignment and I'd like to add a feature to the error checking.
  I have a scanf that asks for a word (which is only 5 characters long max).
  If the user inputs a string that is 6 characters long like <code>candle</code>, it will only copy over <code>candl</code>. </p>
  
  <p>Here is my take on it. Though I'm sure this isn't the most efficient way to do it.</p>
  
  <pre><code>printf("\n\tEnter word: ");
  scanf("%s", input);
  if (strlen(input) &gt; MAX_LETTERS){
      int i = 0;
      while (i &lt; MAX_LETTERS){
          word[i] = input[i];
          i++;
      }
      printf("the word is %s", word);
  }
  </code></pre>
  
  <p>Basically checks to see if the input is greater than the max amount of letters allowed. And then if it is, it loops and then only copies over the max amount of letters. Any help would be very much appreciated. Thank you in advance!</p>