title: fgets() goes into infinite loop reading from stdin
body: <p>I wrote the following code, but it gets stuck into an infinite loop. Can somebody help me out at this topic?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  
  void main()
  {
      FILE *fp;
      char s[10];
  
  
      fp=fopen("text1.txt", "w");
  
      if(fp==NULL)
      {
          printf("Error opening file\n");
          exit(1);
      }
  
      while(fgets(s, sizeof(s), stdin)!=NULL)//Reads until the NULL character.
          fputs(s, fp);//Write to the file pointed by fp..
  
  
      fclose(fp);
      getch();
  }
  </code></pre>