Program compiles, but doesn't act?

Could someone please help me understand why this program is compiling, but not running? The console window opens, but shuts just as fast. I'm thinking I need to write something to the files so that the program will merge what has been written, or will it read two files that are already composed?? It's meant to merge the two input files to the output file, big picture. I need to alphabetize the output, but I can do that once I figure out how this thing writes to the output file! Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#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;
     }
}
Last edited on
Run the program from the commandline.
I don't know how to do that :(
Thanks for the link @admkrk
I think I thought the console closing meant something different because I've never called external files before. I think I was being silly and thought that the program must be doing things I can't see with these files I can't see. Lol. But, now I've got the console to stay open. The program is failing with the first file....not sure how to fix that ailment. Am I calling everything correctly in my declaration and definitions?
Topic archived. No new replies allowed.