Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
can any one post the program for this question
Posted
Updated 19-Sep-11 2:26am
v2
Comments
Mehdi Gholam 17-Sep-11 6:57am    
What do you mean by "merge" in what context?
markkuk 19-Sep-11 8:28am    
No, we won't do your homework for you. See the rules for posting section under the "FAQ" at the top of this page.

merge file1 file2 file3

The merge program should take the parameters from the command line (see argc and argv, it should then read each file and merge the data (in whatever way you require) and write the output to file3. See the man pages for fopen(), fread(), and fwrite() for more information.
 
Share this answer
 
The following program accept 4 command line arguments. First argument ( argv[0] ) is assumed as program name. second and third arguments are file names to be merged. Last argument is the output file, to which the merged contents saved.

C++
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
#include <process.h>
int main(int argc, char* argv[] )
{

    char ch;
    ifstream infile;
    infile.open( argv[1] );
    if( !infile )
    {
        cerr << "\nCan't open " << argv[1];
        exit(-1);
    }
    ofstream outfile;
    outfile.open( argv[3] );
    if( !outfile )
    {
        cerr << "\nCan't open " << argv[3];
        exit(-1);
    }
    while( infile )
    {
        infile.get(ch);
        outfile.put(ch);
    }
    infile.close();

    infile.open( argv[2] );
    if( !infile )
    {
        cerr << "\nCan't open " << argv[2];
        exit(-1);
    }

    while( infile )
    {
        infile.get(ch);
        outfile.put(ch);
    }
    infile.close();
    outfile.close();
    return 0;
}


Hope that this is useful for you
 
Share this answer
 
v2
Comments
Richard MacCutchan 17-Dec-13 12:01pm    
Look at the date of this question.
according to your question this will help you

C:\>type text1.txt
this is a test.
then you can use the type command plus the double arrows to merge a files

C:\>type *.txt >>merge.txt
text1.text
text2.text etc...

and note if you using linux you can use :

cat *.txt >> merge.txt (>> ==means input streams)
 
Share this answer
 
Comments
Richard MacCutchan 17-Dec-13 12:01pm    
Look at the date of this question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900