Tuesday, 27 August 2013

c program to merge two files and save it into the third file specified by the command line arguments

/*
    Date: 18/08/13 07:50
    Description: Merges two files data1 and data2 into the third file data3 using commandline arguments
*/

#include<stdio.h>

int main(int argc ,char *argv)
{
    FILE  *f1,*f2,*fd;
    int  ch;

    /*if(argc!=4)
    {
        printf("not enough parameters were specified");
        getchar();
        return 0;
    }*/

    f1=fopen("data1.txt","r");
    f2=fopen("data2.txt","r");
    fd=fopen("data3.txt","w");

    //file---->1
    while(!feof(f1))
    {
        ch=getc(f1);
        putc(ch,fd);
    }
    fclose(f1);

    //file----->2
    while(!feof(f2))
    {
        ch=getc(f2);
        putc(ch,fd);
    }
    fclose(f2);

    fclose(fd);

    getch();
    return 0;
}




//go to programm location using commandpromt and enter
<program name>  <file1>  <file2>  <destinationfile>

No comments:

Post a Comment