title: Error in simple file handling C program
body: <p>Here's the code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
      FILE *fp;
      int i;
      fp=fopen("DATA","w");
      for(i=1;i&lt;=30;++i)
          putw(i,fp);
      fclose(fp);
      fp=fopen("DATA","r");
      while((i=getw(fp))!=EOF)
          printf("%4d",i);
      fclose(fp);
      return 0;
  }
  </code></pre>
  
  <p>I don't get the expected output. The program prints the number till 25 rather than till 30. If I set <code>i&lt;=20</code>, I get the right output. I do not understand this.</p>
  
  <p>Help is appreciated. Thanks!</p>