New member, and a problem
Seems like this forum is where its at for programming info.
Anyways, I'm having an interesting problem with a project, and I'd like your opinions.
I have NO idea where the error is, but I'll post where I think it is...
I'm working with a file, and I initialize it like this:
void BST::InitEmpFile()
{
employeeData blankEmployee;
cout.setf(ios::fixed, ios::floatfield);
cout.setf( ios::showpoint);
cout << setprecision(2);
blankEmployee.employeeId = 0;
strcpy(blankEmployee.Fname, "--");
strcpy(blankEmployee.Lname, "--");
blankEmployee.Salary = 0.0;
for (int i=0; i<199; i++)
fout.write(reinterpret_cast<const char*>(&blankEmployee), sizeof(employeeData));
}
Where employeeData is a struct containing 2 ints and 2 char arrays.
When inserting into the tree(which works fine), I use this code snippet to determine if the location in the file can hold data or not...
employeeData temp = ReadRecord(tempRecNo);
then I check the resulting employee id in "temp"
Anyways, after this, the program prints the contents of the file. If the above line is commented out, it prints fine. If not, the output is gibberish. The ReadRecord code is this:
employeeData BST::ReadRecord(int recNo)
{
employeeData temp;
fin.seekg(sizeof(employeeData)*recNo);
fin.read(reinterpret_cast<char*>(&temp), sizeof(employeeData));
cout << "\n\n" << temp.employeeId << "\t" << temp.Fname << endl; //for checking purposes... will remove
return temp;
}
Funny thing is, when i call this function from main() it reads fine. But if I call it from within the function to add records, then it doesn't work.
Anyways, the whole code is here if anyone wants to see it...
All code (http://area5150.tripod.com/EmployeeRecords.h)
If anyone can help, i'd appreciate it.
Note: my delete function doesn't work because I havent tried to do it yet. Please no help on that! I wanna figure it out on my own! :-D
Thanks all, this one's been perplexing me for days...
James

