Code:
//For turbo C++ remove below comments
#include <stdio.h>
//#include<conio.h>
void main()
{
// clrscr();
FILE *fd,*fo,*fe;
int n,i;
fd=fopen("data.txt","w");
printf("Contents of Data File : \n");
for (i = 0; i < 100; i++){
scanf("%d",&n);
if (n==-1){
break;
}
putw(n,fd);
}
fclose(fd);
fd=fopen("data.txt","r");
fo=fopen("odd.txt","w");
fe=fopen("even.txt","w");
while ((n=getw(fd))!=EOF){
if (n%2==0){
putw(n,fe);
}
else{
putw(n,fo);
}
}
fclose(fd);
fclose(fo);
fclose(fe);
fe=fopen("even.txt","r");
fo=fopen("odd.txt","r");
printf("\nContents of odd file: \n");
while ((n=getw(fo))!=EOF){
printf("%4d",n);
}
// getch();
printf("\nContents of even file: \n");
while ((n=getw(fe))!=EOF){
printf("%4d",n);
}
fclose(fe);
fclose(fo);
// getch();
}
Comments
Post a Comment