title: How to make Negated scanset of scanf() work in a loop?
body: <p>Here is my C code. <code>Scanset</code> of <code>scanf()</code> does not work within the for loop . It takes only one value for string even in loop. If I replace  <code>scanset</code> of <code>scanf()</code> with <code>gets()</code> it works. How to make this <code>scanset</code>   work in a loop?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main(void)
  {
       char str[128];
       int i;
       for(i=0;i&lt;2;i++)
       {
           printf("Enter a string with spaces: ");
           scanf("%[^\n]s", str);
  
           printf("You entered: %s\n", str);
       }
      return 0;
  }
  </code></pre>