title: Can anyone tell me the problem of this code (it is to write even and odd numbers in separate files.)?
body: <p>I want to print even and odd in separate file only up to 50.Given below is the program.</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  int main()
  {
      FILE *fp1,*fp2,*fp3;
      int i,n;
      fp1=fopen(&quot;data&quot;,&quot;w&quot;);
      for(i=1;i&lt;=50;i++)
         fprintf(fp1,&quot;%d&quot;,i);
      fclose(fp1);
      fp1=fopen(&quot;data&quot;,&quot;r&quot;);
      fp2=fopen(&quot;even&quot;,&quot;w&quot;);
      fp3=fopen(&quot;odd&quot;,&quot;w&quot;);
      while(!feof(fp1))
      {
          fscanf(fp1,&quot;%d&quot;,&amp;n);
          if(n%2==0)
            fprintf(fp2,&quot;%d&quot;,n);
          else
            fprintf(fp3,&quot;%d&quot;,n);
      }   
      fclose(fp1);
      fclose(fp2);
      fclose(fp3);
      fp1=fopen(&quot;data&quot;,&quot;r&quot;);
      fp2=fopen(&quot;even&quot;,&quot;r&quot;);
      fp3=fopen(&quot;odd&quot;,&quot;r&quot;);
      while(!feof(fp1))
      {
          fscanf(fp1,&quot;%d&quot;,&amp;n);
          printf(&quot;%d&quot;,n);
      }
      puts(&quot;\n Even file&quot;);
      puts(&quot;_________________&quot;);
      while(!feof(fp2))
      {
          fscanf(fp2,&quot;%d&quot;,&amp;n);
          printf(&quot;%d&quot;,n);
      }
      puts(&quot;\n Odd file&quot;);
      puts(&quot;_________________&quot;);
      while(!feof(fp3))
      {
          fscanf(fp3,&quot;%d&quot;,&amp;n);
          printf(&quot;%d&quot;,n);
      }
      fclose(fp1);
      fclose(fp2);
      fclose(fp3);
      getch();
  }
  </code></pre>
  <p>But i get the output
  as shown below</p>
  <pre><code>-856714730
   Even file
  _________________
  -856714730
   Odd file
  _________________
  -856714730
  </code></pre>
  <p>Do anyone have a solution for this?</p>