title: String taking more input than it should take
body: <p>I have created this simple program that takes input from 3 employees. First, it asks for the size of the employee's id. Then it dynamically allocates the size to a character array. Suppose I give the size 4 to the array. Here, I understand we can enter 3 characters as the last one would be '\0'. However, during runtime, I can enter characters more than I initially assumed it would allow to. Why is this happening? Is it expected to get an error?</p>
  <p><em><strong>Code</strong></em>:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int input;
      char *ptr;
  
      for (int i = 1; i &lt;= 3; i++)
      {
          printf(&quot;\nEmployee %d\n&quot;, i);
          printf(&quot;    Enter the number of characters in your eID: &quot;);
          scanf(&quot;%d&quot;, &amp;input);
  
          ptr = (char *)malloc((input + 1) * sizeof(char));
  
          printf(&quot;    Enter your eID: &quot;);
          scanf(&quot;%s&quot;, ptr);
  
          printf(&quot;    Employee eID entered: %s&quot;, ptr);
  
          free(ptr);
      }
  
      return 0;
  }
  </code></pre>
  <p><strong>Output</strong>:</p>
  <pre><code>Employee 1
      Enter the number of characters in your eID: 4
      Enter your eID: 12345
      Employee eID entered: 12345
  Employee 2
      Enter the number of characters in your eID: 3
      Enter your eID: 1234
      Employee eID entered: 1234
  Employee 3
      Enter the number of characters in your eID: 2
      Enter your eID: 123
      Employee eID entered: 123
  </code></pre>