HOME

Start

Control Statements

Array

Function

Structure

Pointer

File

Projects

 

 

 

 

 

 

C programing

Ckalari.com is the No.1 website to get the best of C programs, free source codes, projects in c language……  

A C program to separate even and odd to another two files

#include<stdio.h>

#include<conio.h>

void main()

     {

    FILE *f,*od,*ev;

    int num,i;

    clrscr();

    printf("Enter numbers,and -1 for stop\n");

    f=fopen("num.dat","w");

    for(i=1;i>0;i++)

    {

      scanf("%d",&num);

      if(num==-1)

      break;

      putw(num,f);

    }

    fclose(f);

    f=fopen("num.dat","r");

    od=fopen("odd.dat","w");

    ev=fopen("even.dat","w");

    while((num=getw(f))!=EOF)

      {

      if(num%2==0)

      putw(num,ev);

      else

      putw(num,od);  

         }

    fclose(f);

    fclose(od);

    fclose(ev);

    od=fopen("odd.dat","r");

    ev=fopen("even.dat","r");

    printf("The contents of odd file is\n\n");

    while((num=getw(od))!=EOF)

      printf("%d ",num);

    printf("\n\n");

    printf("The contents of EVEN file is\n\n");

    while((num=getw(ev))!=EOF)

      printf("%d ",num);

          fclose(od);

    fclose(ev);

    getch();

     }

Copyright © 2007-2008 www.ckalari.com