Saturday, November 5, 2011

File operation in C


Take 10 numbers from users then store odd numbers in "odd.dat" and evenin numbers in "even.dat" file.

#include<stdio.h>
void main()
{
FILE *fp1,*fp2;
int i,arr[10];
fp1=fopen("odd.dat","w");
fp2=fopen("even.dat","w");

for(i=0;i<=9;i++)
{
printf("Enter value");
scanf("%d",&arr[i]);
}

for(i=0;i<=9;i++)
{
if(arr[i]%2==0)
{
fprintf(fp2,"%d",arr[i]);
}
else
{
fprintf(fp1,"%d",arr[i]);
}

}
fclose(fp1);
fclose(fp2);
}

0 comments:

Post a Comment

You are most welcome for making comments here. I will consider your view and will reply you soon.