title: Want a C program to write into a file, read it and store even and odd numbers in a separate file
body: <p>I tried to make the following code.</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  #include&lt;stdlib.h&gt;
  
  void main()
  {
    FILE *fp1,*fp2,*fp3;
    int n,i,size;
    printf(&quot;Enter no.of digits: &quot;);
    scanf(&quot;%d&quot;,&amp;size);
    fp1=fopen(&quot;NUMBER.txt&quot;,&quot;w&quot;);
    printf(&quot;Enter the numbers: \n&quot;);
    for(i=0;i&lt;size;i++)
    {
      fflush(stdin);
      scanf(&quot; %d&quot;,&amp;n);
      fputc(n,fp1);
    }
    fclose(fp1);
    
    fp1=fopen(&quot;NUMBER.txt&quot;,&quot;r&quot;);
    fp2=fopen(&quot;EVEN.txt&quot;,&quot;w&quot;);
    fp3=fopen(&quot;ODD.txt&quot;,&quot;w&quot;);
    while((n=fgetc(fp1))!=EOF)
    {
      if(n%2==0)
      fputc(n,fp2);
      else
      fputc(n,fp3);
    }
    fclose(fp1);
    fclose(fp2);
    fclose(fp3);
  
    fp1=fopen(&quot;NUMBER.txt&quot;,&quot;r&quot;);
    fp2=fopen(&quot;EVEN.txt&quot;,&quot;r&quot;);
    fp3=fopen(&quot;ODD.txt&quot;,&quot;r&quot;);
    
    printf(&quot;The content of number file are: &quot;);
    while((n=fgetc(fp1))!=EOF)
    printf(&quot; %d&quot;,n);
    
    printf(&quot;\nThe content of even file are: &quot;);
    while((n=fgetc(fp2))!=EOF)
    printf(&quot; %d&quot;,n);
    
    printf(&quot;\nThe content of odd file are: &quot;);
    while((n=fgetc(fp3))!=EOF)
    printf(&quot;  %d&quot;,n);
  
    fclose(fp1);
    fclose(fp2);
    fclose(fp3);
  }
  </code></pre>
  <p>The problem I face is that the contents of the files are in hex or binary. I want it to be readable with text editor not a hex editor. The other problem I face is the scanf() doesn't accept 3 digit numbers. The output is given below.</p>
  <p>Enter no.of digits: 5
  Enter the numbers:
  123
  34
  456
  67
  789
  The content of number file are:  123 34 200 67 21
  The content of even file are:  34 200
  The content of odd file are:   123  67  21</p>
  <p>I tried to write the following code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      FILE *fp1,*fp2,*fp3;
      int size,n,a,b;
      printf(&quot;Enter the size: &quot;);
      scanf(&quot;%d&quot;,&amp;size);
      fp1=fopen(&quot;numbers1.txt&quot;,&quot;w&quot;);
      fp2=fopen(&quot;even1.txt&quot;,&quot;w&quot;);
      fp3=fopen(&quot;odd1.txt&quot;,&quot;w&quot;);
      
      printf(&quot;Enter the integers: &quot;);
      
      for(int i=0;i&lt;size;i++)
      {
        scanf(&quot;  %d&quot;,&amp;n);
        //putc(n,fp1); reads as 12, 234 etc but digits in file is not visible
        fprintf(fp1,&quot; %d\n&quot;,n);//reads 12, 234 as 12234 but digits in file are visible
        
      }
      
      fclose(fp1);
      fp1=fopen(&quot;numbers1.txt&quot;,&quot;r&quot;);
      
      n=getc(fp1);
      
      while(n!=EOF)
      {
          if(n%2==0)
          putc(n,fp2);
          
          else if(n%2==1)
          putc(n,fp3);
          
          n=getc(fp1);
      }
  
      
      fclose(fp1);
      fclose(fp2);
      fclose(fp3);
      
      
      return 0;
  }
  </code></pre>
  <p>In the above code the content in the files are in text, but the odd and even files read char by char. The contents of odd, even and number files are given blow.</p>
  <p>odd file:
  133577</p>
  <p>even file:
  2
  4
  46
  6
  8</p>
  <p>Number file:
  123
  34
  456
  67
  78</p>
  <p>Please help me</p>