Binary file Help Please!

Hey there, I'm working on a program but I cannot seem to figure out why the build is not building. There are no errors within the code itself, however there are two errors which keep showing up in the background.
They are:

(Error 1)
Undefined symbols for architecture x86_64:
"OpenFile(std::__1::basic_ifstream<char, std::__1::char_traits<char> >&, int&, int&, int&, EachUnit (*) [10], int&)", referenced from:
_main in main.o
(Error 2)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have put all my code here for further review. Any help would be appreciated. I am not too familiar with binary files as of yet and perhaps I have done something wrong with my code?
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  #include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <cmath>

using namespace std;

// CONSTANTS

const string BIN_OFFICE = "OFFICE.BIN";     // office file name

const int MAX_OFFICES = 50;         // max number of offices in building
const int MAX_FLOORS = 5;           // max number of floors
const int MAX_UNITS = 10;           // max number of units per floor
const int MAX_STATUS = 3;           // max number of possible statuses

//enum OFFICE_UNIT {A, B, C, D, E, F, G, H, I, J};
enum OFFICE_STATUS {OCCUPIED, AVAILABLE, REMODELING};       // status of the office

const string STAT1 = "OCCUPIED";
const string STAT2 = "AVAILABLE";
const string STAT3 = "REMODELING";

const char OCC = 'O';
const char AVA = 'A';
const char REM = 'R';
const char EXIT = 'D';

struct EachUnit {
    
    int floor;
    char unit;
    char status;         // status of unit
};

// Prototypes
void programDesc();         // program description
void OpenFile(ifstream& BinFile, int& officeTotal, int& floorCount, int& unitCount, EachUnit OfficeArray[][MAX_UNITS], int& occupiedCount);
void InitializeArray(EachUnit OfficeArray[][MAX_UNITS], int& floorCount, int& unitCount);
void ReadFile(ifstream& BinFile, EachUnit  OfficeArray[][MAX_UNITS],int& theAvailable, int& theRemodeled, int& theOccupied, int& officeTotal);
void DisplayStatus(int& theAvailable, int& theRemodeled, int& occupiedCount, int& officeTotal);
void PreferenceMenu(EachUnit OfficeArray[][MAX_UNITS], char& choice, int& theOccupied, int& theAvailable, int& theRemodeled);
void ChoiceFunc(EachUnit OfficeArray[][MAX_UNITS], char& choice, int& theOccupied, int& theAvailable, int& theRemodeled);
void OccStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theOccupied);
void AVAStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theAvailable);
void REMStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theRemodeled);
void ModifyFunc(EachUnit OfficeArray[][MAX_UNITS], int& theAvailable, int& theOccupied, int&theRemodeled, int& officeTotal);
int UnitConvert(char& unitCount);
char ReUnitConversion(int& uCount);
void SaveData(ofstream& BoutFile, EachUnit OfficeArray[][MAX_UNITS]);


int main()
{
    int officeTotal;        // total number of offices
    int floorCount,         // number of floor
        unitCount,          // number of unit
        availableCount = 0,     // total number of available offices
        remodelCount = 0,       // total number of remodeling offices
        occupiedCount = 0;      // total number of occupied offices
    int * theAvailable;
    int * theRemodeled;
    int * theOccupied;
    char choice = ' ';
    
    theAvailable = &availableCount;
    theRemodeled = &remodelCount;
    theOccupied = &occupiedCount;
    
    
    EachUnit OfficeArray[MAX_FLOORS][MAX_UNITS];
    
    ifstream BinFile;
    ofstream BoutFile;
    
    bool fileExists = true;
    
    programDesc();
    
    OpenFile(BinFile, officeTotal, floorCount, unitCount, OfficeArray, occupiedCount);
    ReadFile(BinFile, OfficeArray,*theAvailable,*theRemodeled,*theOccupied, officeTotal);
    
    DisplayStatus(*theAvailable, *theRemodeled, occupiedCount, officeTotal);

    PreferenceMenu(OfficeArray, choice, *theOccupied, *theAvailable, *theRemodeled);
    ModifyFunc(OfficeArray, *theAvailable, *theOccupied, *theRemodeled, officeTotal);
    
    SaveData(BoutFile, OfficeArray);
    
    return 0;
}


void programDesc()
{
    cout << "This program will do this and that" << endl << endl;
}

void openFile(ifstream& BinFile, int& officeTotal, int& floorCount, int& unitCount, EachUnit OfficeArray[][MAX_UNITS], int& occupiedCount)
{
    BinFile.open("OFFICE.bin" , ios::in | ios::binary);
    
    if (BinFile)
    {
        cout << "File was opened successfully." << endl << endl;
    }
    else
    {
        //fileExists = false;
        cout << "All of the units are assumed to be occupied." << endl << endl;
        
        InitializeArray(OfficeArray, floorCount, unitCount);
        
        occupiedCount = MAX_OFFICES;
    }
    
}

void InitializeArray(EachUnit OfficeArray[][MAX_UNITS], int& floorCount, int& unitCount)
{
    for(floorCount = 0; floorCount < MAX_FLOORS; floorCount++)
    {
        for(unitCount = 0; unitCount < MAX_UNITS; unitCount++)
        {
            OfficeArray[floorCount][unitCount].status = OCCUPIED;
        }
    }
}

void ReadFile(ifstream& BinFile, EachUnit OfficeArray[][MAX_UNITS], int& theAvailable, int& theRemodeled, int& theOccupied, int& officeTotal)
{
    //int myfloor;
    int fl = 0;
    char theUnit = ' ';
    int unitConverted;
    char thestat = ' ';
    
    
    if (BinFile)
    {
        while (BinFile)
        {
            
            BinFile.read((char*)&fl,sizeof(fl));
            BinFile.read((char*)&theUnit, sizeof(theUnit));
            BinFile.read((char*)&thestat,sizeof(thestat));
            
            unitConverted = UnitConvert(theUnit);
            
            OfficeArray[fl][unitConverted].floor = fl;
            OfficeArray[fl][unitConverted].unit = theUnit;
            OfficeArray[fl][unitConverted].status = thestat;
            
            if (thestat == AVA) {
                theAvailable++;
            }
            else if (thestat == REM){
                theRemodeled++;
            }
            else
            {
                theOccupied++;
            }
            
            officeTotal++;
        }
    }
    
    BinFile.close();
    
}

void DisplayStatus(int& theAvailable, int& theRemodeled, int& occupiedCount, int& officeTotal)
{
    if (occupiedCount < MAX_OFFICES){
    cout << "Current Status:" << endl;
    cout << "     " << occupiedCount << " " << STAT1 << endl;
    cout << "     " << theAvailable << " " << STAT2 << endl;
    cout << "     " << theRemodeled << " " << STAT3 << endl;
    cout << "    ----" << endl;
    cout << "     " << officeTotal << " Total Units" << endl;
    }
    else{
        cout << "All units occupied. Program will now EXIT." << endl << endl;
    }
}
2nd part of the code (was too long for one post

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

void ChoiceFunc(EachUnit OfficeArray[][MAX_UNITS], char& choice, int& theOccupied, int& theAvailable, int& theRemodeled)
{

    bool isValid = false;

    do {
        cin >> choice;
        choice = toupper(choice);
        
        switch (choice)
        {
            case OCC:
            case AVA:
            case REM:
            case EXIT:
            isValid = true;
            break;
            
        default:
            {
                isValid = false;
                cout << "Invalid input. Please enter";
                cout << " O , A, R, or E: " << endl;
                PreferenceMenu(OfficeArray, choice, theOccupied, theAvailable, theRemodeled);
            }
            break;
        }
    }while(isValid != true);
    
    switch (choice) {
        case OCC:
            OccStatusDisplay(OfficeArray, theOccupied);
            break;
        case AVA:
            AVAStatusDisplay(OfficeArray, theAvailable);
            break;
        case REM:
            REMStatusDisplay(OfficeArray, theRemodeled);
            break;
        default:
        {
            cout << "Program will now EXIT." << endl << endl;
        }
            break;
    }
}
void PreferenceMenu(EachUnit OfficeArray[][MAX_UNITS], char& choice, int& theOccupied, int& theAvailable, int& theRemodeled)
{
    do {
        
        cout << "PREFERENCE MENU " << endl;
        cout << "----------------" << endl;
        cout << "O for Occupied" << endl;
        cout << "A for Available" << endl;
        cout << "R for Remodeling" << endl;
        cout << "D for Done/Exit" << endl;
        cout << "----------------" << endl;
        cout << "Please Choose one: " << endl;
        
        ChoiceFunc(OfficeArray, choice, theOccupied, theAvailable, theRemodeled);
    }while(choice != EXIT);
}


void OccStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theOccupied)
{
    int row;
    int column;
    
    if (theOccupied == 0)
    {
        cout << "There are no occupied offices in the building." << endl;
    }
    
    else
    {
        for(row = 0; row < MAX_FLOORS; row++)
        {
            for(column = 0; column < MAX_UNITS; column++)
            {
                if (OfficeArray[row][column].status == OCC)
                {
                    cout << "Floor: " << OfficeArray[row][column].floor << " - ";
                    cout << "Unit: " << OfficeArray[row][column].unit << " - ";
                    cout << "Status: " << OfficeArray[row][column].status << endl;
                }
            
            }
        }
    }
    
}

void AVAStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theAvailable)
{
    int row;
    int column;
    
    if (theAvailable == 0)
    {
        cout << "There are no occupied offices in the building." << endl;
    }
    
    else
    {
        for(row = 0; row < MAX_FLOORS; row++)
        {
            for(column = 0; column < MAX_UNITS; column++)
            {
                if (OfficeArray[row][column].status == AVA)
                {
                    cout << "Floor: " << OfficeArray[row][column].floor << " - ";
                    cout << "Unit: " << OfficeArray[row][column].unit << " - ";
                    cout << "Status: " << OfficeArray[row][column].status << endl;
                }
                
            }
        }
    }
    
}

void REMStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theRemodeled)
{
    int row;
    int column;
    
    if (theRemodeled == 0)
    {
        cout << "There are no occupied offices in the building." << endl;
    }
    
    else
    {
        for(row = 0; row < MAX_FLOORS; row++)
        {
            for(column = 0; column < MAX_UNITS; column++)
            {
                if (OfficeArray[row][column].status == REM)
                {
                    cout << "Floor: " << OfficeArray[row][column].floor << " - ";
                    cout << "Unit: " << OfficeArray[row][column].unit << " - ";
                    cout << "Status: " << OfficeArray[row][column].status << endl;
                }
                
            }
        }
    }
    
}

void ModifyFunc(EachUnit OfficeArray[][MAX_UNITS], int& theAvailable, int& theOccupied, int&theRemodeled, int& officeTotal)
{
    int theFloor;
    char theUnit;
    int unitConvert;
    char theStatus;
    char minusThis;
    
    
    cout << "Please enter the floor: ";
    cin >> theFloor;
    cout << endl << "Please enter the unit character (ex: A, B, etc): ";
    cin >> theUnit;
    
    cout << endl << "What status do you want the unit to be?" << endl;
    cout << " A for Available, O for Occupied, R for Remodeling." << endl;
    cout << "Choose one: ";
    cin >> theStatus;
    theStatus = toupper(theStatus);
    
    // changing unit letter into number for storage
    unitConvert = UnitConvert(theUnit);
    
    // finding status to be decremented
    minusThis = OfficeArray[theFloor][unitConvert].status;
    
    // changing status of user's input
    OfficeArray[theFloor][unitConvert].status = theStatus;
    
    // Decrement previous status
    switch (minusThis) {
        case OCC:
            theOccupied--;
            break;
        case AVA:
            theAvailable--;
        default:
            theRemodeled--;
            break;
    }
    // Increment current status
    switch (theStatus) {
        case OCC:
            theOccupied++;
            break;
        case AVA:
            theAvailable++;
        default:
            theRemodeled++;
            break;
    }
    
    DisplayStatus(theAvailable, theRemodeled, theOccupied, officeTotal);
    
}

int UnitConvert(char& unitCount)
{
    switch (unitCount) {
        case 'A':
            return 0;
            break;
        case 'B':
            return 1;
            break;
        case 'C':
            return 2;
            break;
        case 'D':
            return 3;
            break;
        case 'E':
            return 4;
            break;
        case 'F':
            return 5;
            break;
        case 'G':
            return 6;
            break;
        case 'H':
            return 7;
            break;
        default:
            return 10;
            break;
    }
}

char ReUnitConversion(int& uCount)
{
    switch (uCount) {
        case 0:
            return 'A';
            break;
        case 1:
            return 'B';
            break;
        case 2:
            return 'C';
            break;
        case 3:
            return 'D';
            break;
        case 4:
            return 'E';
            break;
        case 5:
            return 'F';
            break;
        case 6:
            return 'G';
            break;
        case 7:
            return 'H';
            break;
        default:
            return 'X';
            break;
    }
}

void SaveData(ofstream& BoutFile, EachUnit OfficeArray[][MAX_UNITS])
{
    int theFloor = 0;
    char theUnit = ' ';
    char theStat = ' ';
    
    BoutFile.open("OFFICE.bin", ios::out | ios::binary);
    
    for(int floorCount = 0; floorCount < MAX_FLOORS; floorCount++)
    {
        for(int unitCount = 0; unitCount < MAX_UNITS; unitCount++)
        {
            if (OfficeArray[floorCount][unitCount].status != OCCUPIED)
            {
                theUnit = ReUnitConversion(unitCount);
                
                theFloor = floorCount;
                
                theStat = OfficeArray[floorCount][unitCount].status;
                
                BoutFile.write((char*)&theFloor, sizeof(theFloor));
                BoutFile.write((char*)&theUnit, sizeof(theUnit));
                BoutFile.write((char*)&theStat, sizeof(theStat));
                
            }
        }
    }
    BoutFile.close();
}
C and C++ are case sensitive... your error is on line #103... can you spot it yourself now?
No , I can't spot it. I don't see anything wrong with line #103. I'm sorry, I'm still new to c++. Could you please point out for me?

Perhaps I'm missing a certain library or something?
Last edited on
Nvm , found it. Wow. Can't believe I missed that, thanks
No worries... that's an easy one to miss.

Good luck with the rest of the program. ;~)
Topic archived. No new replies allowed.