Can anyone tell me why this is printing doubles out to the output file?
IndexFile.seekp(20, ios::beg);
for (i = 0; i < NumOfSlots; i++)
{
if (RandomFile.peek() == 42)
{
Position = i;
RandomFile.seekg(37, ios::cur);
//cout << Position << " ";
}
else if (RandomFile.peek() != 42)
{
RandomFile.get(R.SSN, 10);
NumberWritten = NumberWritten + 1;
Position = i;
//cout << Position << " ";
IndexFile << R.SSN;
I.RelativeAddress = Position;
IndexFile << setw(3) << I.RelativeAddress;
IndexFile << setw(3) << -1;
IndexFile << setw(3) << -1;
IndexFile.seekg(20, ios::beg);
IndexFile.get(I.SSN, 10);
IndexFile >> I.RelativeAddress;
IndexFile >> I.LLink;
IndexFile >> I.RLink;
Position2 = Position2 + 1;
for (i = 0; i < NumberWritten; i++)
{
if (strcmp(R.SSN, I.SSN) != 0)
{
if ((strcmp(R.SSN, I.SSN) < 0) && (I.LLink == -1))
{
I.LLink = Position2;
IndexFile.seekp(3, ios::cur);
IndexFile << setw(3) << I.LLink;
}
else if ((strcmp(R.SSN, I.SSN) > 0) && (I.RLink == -1))
{
I.RLink = Position2;
IndexFile.seekp(3, ios::cur);
IndexFile << setw(3) << I.RLink;
}
}
}
RandomFile.seekg((Position + 1) * 37, ios::beg);
IndexFile.seekp((Position2 + 1) * 20, ios::beg);
}
}
The output file should look like this:
123456720 3 -1 -1
123456708 4 -1 -1
123456705 5 -1 -1
I am trying to fix the links but it keeps printing 20, 08, 20, 08, 05, etc. I am trying to crete an external binary tree in the output file. Thanks for any input.