Binary Tree, project won't run all the way??

I get no errors I don't see any memory leaks.
This is my HW Project and it works fine all of it except I don't know why the cout won't run after Line #302. It's my first time using freopen so I believe that might be the issue but I don't know how to get my data besides using that.
Anything will help.

FYI I use cLion/MinGW as my IDE on Win10 x64.

MY full project is here -> https://drive.google.com/open?id=1WCmAUK9YxcfjhplBWNeStJRjxJmupyj-


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

    /*
     *  6. After all transactions are done it'll store the contents on OrderedMaster.txt in ordered form.
     *  7. Then delete tree.
     *  8. Then it will read the OrderedMaster.txt and create a balanced binary tree.
     *  9. Lastly after creating the balanced tree it'll log it. -> Log.txt
     */

    //masterAccounting.PrintTree(); // for testing purposes

    BinaryTree *test = nullptr;
    test = &masterAccounting;
    testing(test);
    delete (test);

    Log.open("Log.txt", ofstream::out | ofstream::app);
    OrderedMaster.open("OrderedMaster.txt");
    if (Log.is_open()) {

        if (OrderedMaster.is_open()) {

            while (true) {

                if(OrderedMaster.eof()) break;

                OrderedMaster >> accountNum >> firstName >> lastName >> transaction;

                Log << accountNum
                    << "\t" << firstName
                    << "\t" << lastName
                    << "\t" << transaction << endl;

            } // while
        }// if
        else {

            cout << "OrderedMaster failed to open\n";
        }// else

    }// if
    else {

        cout << "Log failed to open\n";

    }// else

    Log.close();
    OrderedMaster.close();

    cout << "\n\nwork\n"; // testing

    return 0;
}

void testing(BinaryTree *a) {

    freopen("OrderedMaster.txt", "w", stdout);
    a->PrintTree();
    fclose(stdout);

}// testing


void clearCIN() {

    cin.clear();
    cin.ignore(32768, '\n');

}//clearCIN
Line #50 won't run. But my files still get the output after line #13. These line numbers are according to the preview code. they'll be around the #300s in my full project.
You don't give enough code to test sensibly, and I'm not going to an external link. However, in general, testing on eof as you do with
if(OrderedMaster.eof())
is not a good idea, as reading the last data item doesn't necessarily set the eof bit. Better to attempt to read, and test the state of the stream.

I suggest first of all that you replace lines 20-38 in your preview code by
1
2
3
4
5
6
7
8
9
10
11
if ( OrderedMaster.is_open() )
{
   while ( OrderedMaster >> accountNum >> firstName >> lastName >> transaction )  // <==== test the state of the stream
   {
      Log << accountNum << "\t" << firstName << "\t" << lastName << "\t" << transaction << endl;
   } 
}
else
{
   cout << "OrderedMaster failed to open\n";
}


If that isn't the problem, then you will have to put lots of cout statements in this region so that you can see where exactly you get to. You have no debugging lines in at present, so you have very little idea where the problem lies. Obviously, you should also check that any files you read have something in - don't take it for granted.
Why are you using freopen(), this C function doesn't understand how to use C++ streams. Stick with C++ streams.

By the way you not even calling that C function correctly, that function returns a FILE* that is used to interface with the file. And by the way opening and closing one of the standard input or output streams can lead to problems, if the call was actually succeeding.



@lastchance It wouldn't let me post all my code too much so I used Google Drive and I'll replace it with the suggested but my code runs all the way (I checked the files) until near the end and thank you for the help.

@jlb My noobness does not know how to read all the data from a binary tree and write it into a file in main(). I got this through googling, the C function. Thank you for the information :]
Topic archived. No new replies allowed.