Store Given Integer Numbers in even.txt if it is Even otherwise to odd.txt until user says "no" and Displaying the Stored Content in File


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
	
void main()
{
 int num;
 char ans[5];
 FILE *po, *pe;
 clrscr();
 po = fopen("odd.txt","w+");
 if(po==NULL)
 {
  printf("Something went wrong!");
  exit(1);
 }
 pe = fopen("even.txt","w+");
 if(pe==NULL)
 {
  printf("Something went wrong!");
  exit(1);
 }
 do
 {
  printf("Enter number:\n");
  scanf("%d",&num);
  if(num%2!=0)
  {
   fprintf(po,"%d\t",num);
  }
  else
  {
   fprintf(pe,"%d\t",num);
  }
  printf("Enter another number? (no to terminate)\n");
  fflush(stdin);
  scanf("%s",ans);
  strlwr(ans);
 }while(strcmp(ans,"no")!=0);

 rewind(po);
 rewind(pe);

 printf("\nContent read from even.txt:\n");
 while(!feof(pe))
 {
  fscanf(pe,"%d\t",&num);
  printf("%d\t", num);
 }

 printf("\nContent read from odd.txt:\n");
 while(!feof(po))
 {
  fscanf(po,"%d\t",&num);
  printf("%d\t", num);
 }

 fclose(pe);
 fclose(po);
 printf("\nProgram completed :)");
 getch();
}