C program to read integer numbers from a file named DATA and then write all odd numbers to a file named ODD and all even numbers to a file named EVEN
#include<stdio.h> #include<conio.h> #include<process.h> void main() { int a,n,i; FILE *fp1,*fp2,*fp3; clrscr(); fp1=fopen(“DATA”,”w”); if(fp1==NULL) { printf(“File could not open!!”); exit(0); } printf(“How many numbers?”); scanf(“%d”,&n); printf(“Enter contents of DATA file:n”); for(i=0;i<n;++i) { scanf(“%d”,&a); putw(a,fp1); } fclose(fp1); fp1=fopen(“DATA”,”r”); fp2=fopen(“ODD“,”w”); fp3=fopen(“EVEN”,”w”); if(fp1==NULL||fp2==NULL||fp3==NULL) { printf(“File could not open!!”); exit(0); } while((a=getw(fp1))!=EOF) { if(a%2!=0) putw(a,fp2); else putw(a,fp3); } fclose(fp1); fclose(fp2); …