60. A file with name data contains numeric value. Write a program to read that value and write even number into even.txt file and odd number into odd.txt file.
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp1,*fp2,*fp3;
fp1=fopen("data.txt","r");
fp2=fopen("odd.txt","w");
fp3=fopen("even.txt","w");
int a;
while(1)
{
a=fgetc(fp1);
if(a==EOF)
break;
else
{
if(a%2==0)
{
fputc(a,fp3);
}
else
{
fputc(a,fp2);
}
printf("%c",a);
}
}
}
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp1,*fp2,*fp3;
fp1=fopen("data.txt","r");
fp2=fopen("odd.txt","w");
fp3=fopen("even.txt","w");
int a;
while(1)
{
a=fgetc(fp1);
if(a==EOF)
break;
else
{
if(a%2==0)
{
fputc(a,fp3);
}
else
{
fputc(a,fp2);
}
printf("%c",a);
}
}
}
Last statement
ReplyDelete|printf("%c",a);|
what is requirements of it?
it is used to print the value on output screen also.
Delete