Thursday, 6 December 2018

Programming for Problem Solving (3110003) - Program no 60.

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);
        }
    }
  }

2 comments:

  1. Last statement
    |printf("%c",a);|
    what is requirements of it?

    ReplyDelete
    Replies
    1. it is used to print the value on output screen also.

      Delete