Program to create a file of number and copy odd number into second file and even number into third file - 100 Most Important C# Programs

100 Most Important C# Programs

70. Program to create a file of number and copy odd number into second file and even number into third file.

Code:

#include<stdio.h>

#include<conio.h>

main( )

{

FILE *fp1,*fp2,*fp3;

int i;

fp1=fopen(“DATA1”,”w”);

printf(“enter the number”);

scanf(“%d”,&i);

while(i!=eof( ))

{

putw(i,fp1);

}f

colse(fp1);

fp1=fopen(“DATA1”,”r”);

fp2=fopen(“DATA2”,”w”);

fp3=fopen(“DATA3”,”w”);

while((i=getw(fp1))!=EOF())

if(i%2= =0)

putw(i,fp3);

else

putw(i,fp2);

fcolse(fp1);

fcolse(fp2);

fcolse(fp3);

getch( );

}