title: scanning a string with whitespaces
body: <p>I am facing problem in printing a string with whitespaces. What is wrong with the following code and how can i avoid it?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
      char str[50]; 
      int t;
      scanf("%d",&amp;t);
      while(t--)
      {
          scanf("%[^\n]%*c", str);
          printf("%s\n", str);
      }
      return 0;
  }
  </code></pre>
  
  <p>input: 2<br/>
      i am ed<br/>
      i am from us<br/>
      the output which gets printed are some weird characters<br/>
      can somebody help me out in this!</p>