title: reading an entire line including spaces using c
body: <p>I am trying to read an entire line from the user including white space, however my code right now does the scanf correctly only on the first iteration of the for loop. After that it simply prints x 9 times rather than asking the user again for more input. It is as if the scanf doesn't get called on the subsequent iterations Why is this? How can I fix this? My code is below. Thanks</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(){
      char x[1024];
      for (int n=0; n&lt;10; n++){
          scanf("%[^\n]s",x);
          printf("x = %s\n",x);
      }
  </code></pre>