tat2dlady 0 Light Poster

Can anyone help me with this snippet of code? I have 2 files, a random record containing random records in it and an index file, which contains the binary tree of the random record. Here is what the index file looks like:

123456720 4 -1 -1
123456708 6 -1 -1
123456703 10 -1 -1
123456723 30 -1 -1
... etc.

What I do is add 1 number from the random record file into the first position of the index file. Then, I need to search the index file for the record I just inserted. The first record I come across that has a left or right link of -1 is the parent of the record I just inserted. My problem is:

I read the record from the random record number and get it inserted into the index file. Then, I want to start at the top of the index file and read each SSN. If it is not the record I just inserted, I want to check that record's link. I cannot get it to read the SSN from the index file. Here is what I have:

struct RandomRecord
{
  char SSN[10];
  char LastName[16];
  char FirstName[11];
  char MidInitial;
};
// end struct RandomRecord

struct IndexRecord
{
  char SSN[10];
  int  RelativeAddress;
  int  LLink;
  int  RLink;
};
// end struct IndexRecord

.
.
.

for (i = 0; i < 100; i++)
  {
    if (RandomFile.peek() == 42)  // the asterisk
    {
      Position = Position + 1;
      RandomFile.seekg(Position * 37, ios::beg);
    }
    else 
    {     
      RandomFile.get(R.SSN, 10);
      Position = Position + 1;
      NumberWritten = NumberWritten + 1;
      
      IndexFile << R.SSN;
      I.RelativeAddress = Position;
      IndexFile << setw(3) << I.RelativeAddress;
      IndexFile << setw(3) << I.LLink;
      IndexFile << setw(3) << I.RLink;
          
      // will write this fine to the index file

      IndexFile.seekg(20, ios::beg);
      
      IndexFile.get(I.SSN, 10);
      IndexFile >> I.RelativeAddress;
      IndexFile >> I.LLink;
      IndexFile >> I.RLink;
      
      cout << I.SSN; 
      // Never prints this SSN
    }

After reading the I.SSN, I want to compare it to R.SSN but it never gets the SSN from the index file. Does anyone have any suggestions? Sorry the post is so long. Just wanted to clarify what I'm trying to do. Thanks.