|
-
May 11th, 2014, 09:34 PM
#1
Code for merging isn't doing anything
'm trying to finish this project which is supposed to read two files, and merge them alphabetically. I've written this code, and it compiles. But it isn't actually doing anything?? I'm not really sure what I'm supposed to be seeing since I'm so new, so I don't know what I'm doing wrong. The console opens and closes immediately upon running. Any help would be GREATLY appreciated!!
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
#define hisFamily "The Adopted.txt" //His family
#define herFamily "The Originals.txt" //Her family
#define ourFamily "The Big Picture.txt" //Our family
//Function Prototypes
//Copies text
int copyLine(ifstream&, ifstream&, ofstream&);
int main()
{
ifstream theAdopted("The Adopted.txt");
ifstream theOriginals("The Originals.txt");
ofstream theBigPicture("The Big Picture.txt");
int SIZE1 = 200, SIZE2 = 200;
int insA[SIZE1];
int insB[SIZE2];
int outs[SIZE1 + SIZE2];
int lineCount;
int index1 = 0;
int index2 = 0;
int A = 0;
int B = 0;
//Retreive his family's grades.
theAdopted.open(hisFamily);
if(theAdopted.fail())
{
cerr << "ERROR: Cannot open" << theAdopted << ". \n";
return EXIT_FAILURE;
}
//Retreive her family's grades.
theOriginals.open(herFamily);
if(theOriginals.fail())
{
cerr << "ERROR: Cannot open" << theOriginals << ". \n";
return EXIT_FAILURE;
}
//Call theBigPicture.
theBigPicture.open(ourFamily);
if(theBigPicture.fail())
{
cerr << "ERROR: Cannot open" << theBigPicture << ". \n";
return EXIT_FAILURE;
}
//Copy data hisFamily to ourFamily.
string line;
lineCount = 0;
getline(theAdopted, line);
while(line.length() != 0)
{
lineCount++;
theBigPicture << line << endl;
getline(theAdopted,line);
cout << "Input data mergered to file 'The Big Picture.exe'." << endl;
//Close files.
theAdopted.close();
theOriginals.close();
return 0;
}
int copyLine
(ifstream& theAdopted,
ifstream& theOriginals,
ofstream& theBigPicture);
{
const char NWLN = '\n';
char nextCh;
int charCount = 0;
//Merge
theAdopted.get(nextCh);
while ((nextCh != NWLN) && !theAdopted.eof())
{
theBigPicture.put(nextCh);
charCount++;
theAdopted.get (nextCh);
}
if(!theAdopted.eof())
{
theBigPicture.put(NWLN);
charCount++;
}
return charCount;
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|