I got the program in my last thread working, now I'm trying to get a program to read the binary file which it created in the last one. My only problem is that it won't read. At all.
NOTE:
I'm working on an old compiler. Saying 'put functions here blahblah' 'dont use.h' doesnt help at all, currently the code below compiles, there are 0 syntax errors.
Code:
#include <fstream.h>
#include <stdlib.h>
struct employee
{
int id;
int salary;
char firstname[11];
char lastname[11];
};
int main (void)
{
fstream fsbin,
fout;
fsbin.open("hwk07.bin", ios::in);
fout.open("hwk07out.txt", ios::out);
void readwritebin (fstream&, fstream&);
readwritebin (fsbin, fout);
return 0;
}
void readwritebin (fstream& fsbin, fstream& fout)
{
employee worker = {0},
labor[100] = {0};
int idNum = 1;
while (idNum != 0)
{
char id[4];
cout << "\nPlease enter an id number, or '0' to exit: ";
cin >> idNum;
if (idNum != 0)
{
fsbin.seekg(idNum * sizeof(employee), ios::beg);
fsbin.read((char*)&worker.id, sizeof(int));
cout << "\nThe data for employee " << idNum << "is: \n"
<< worker.id << "\t" << worker.firstname << "\t"
<< worker.lastname << "\t" << worker.salary << "\t"
<< (worker.salary / 12.0) << "\n";
} //if
} // while
} // readwritebin