//WAP TO READ AND WRITE INTEGER VALUES
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f1,*f2,*f3;
int number,i;
clrscr();
printf("\n\nENTER THE CONTENTS IN A FILE\n\n");
f1=fopen("data","w");
for(i=0;i<=9;i++)
{
scanf("%d",&number);
if(number==-1)
break;
putw(number,f1);
}
fclose(f1);
f1=fopen("data","r");
f2=fopen("odd","w");
f3=fopen("even","w");
while((number=getw(f1))!=EOF)
{
if(number%2==0)
putw(number,f3);
else
putw(number,f2);
}
fclose(f1);
fclose(f2);
fclose(f3);
f2=fopen("odd","r");
f3=fopen("even","r");
printf("\n\nCONTENTS OF ODD FILE\n\n");
while((number=getw(f2))!=EOF)
{
printf("%d",number);
printf("\t");
}
printf("\n\nCONTENTS OF EVEN FILE\n\n");
while((number=getw(f3))!=EOF)
{
printf("%d",number);
printf("\t");
}
fclose(f2);
fclose(f3);
getch();
}
/**************************************************************************
OUTPUT
**************************************************************************
ENTER THE CONTENTS IN A FILE
1 2 3 4 5 6 7 8 9 0^Z
CONTENTS OF ODD FILE
1 3 5 7 9
CONTENTS OF EVEN FILE
2 4 6 8 0
*/
No comments:
Post a Comment