Completely Solved C, C++ Programs Assignment.




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

Filed Under:

Problem 95. C Program to create a file of numbers and copy odd number into second file and even number into third file
#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);
}
fcolse(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( );
}

C compiler: gcc 4.1.2

 Back to main directory: Sample C Program | Software Practical | Solved C Assignment


Get Free Programming Tutorials and Solved assignments