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

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

Code:

#include<conio.h>

#include<stdio.h>

main( )

{

FILE *fp1,*fp2,*fp3;

int i;

fp1=open(“data1”,w”);

printf(“enter the number”);

scanf(“%d”,&i);

while(i!=eof)

{

putw(i,fp1);

scanf(“%d”,&i);

}f

colse(fp1);

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

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

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

while((i=getc(fp1))!=eof)

if(i%2==0)

putc(i,fp3);

else

putw(i,fp2);

fcolse(fp1);

fcolse(fp2);

fcolse(fp3);

getch( );

}