title: Input large strings in C
body: <p>For a particular problem, I have to take string input from the user which can be of size between <code>1 and 10^5</code> . 
  I used the following code</p>
  
  <pre><code>char *a;
  a = malloc(100000*sizeof(char));
  </code></pre>
  
  <p>and inside a loop ( t refers to number of test cases )</p>
  
  <pre><code>while( t-- )
  {
    scanf( "%d", &amp;n );
    scanf( "%s", a );
    .....
  }
  </code></pre>
  
  <p>n is the length of the string that is input by the user at run time. The problem is this is giving me "Time Limit Exceeded" </p>
  
  <p>I made few changes to the above code,</p>
  
  <pre><code> while( t-- )
   {
     scanf( "%d", &amp;n );
     char a[n];
     scanf( "%s", a );
     ....
   }
  </code></pre>
  
  <p>This works perfectly fine without "TLE" . But I don't understand why. The reason for using the first code was that time would be saved since allocation of memory is done only once. Am I wrong? 
  Please explain.</p>