I am trying to create a random access file from a sequential file. I have the random access file skeletonized with "dummy records". An example of my dummy record is:


The "*'s" are a SSN, "Z's" are the last name, etc, etc. The 100 and the -1's are a link at the end of each file (to be used with synonym chaining). The 100 is the next available slot in my overflow area. Anyway, the problem is that I read the first SSN, use a hash function on that SSN (hashes to position 69 in the file). I use seekp to get to position 69. Then, I want to peek at the first character on line 69 and see if it is a "*". If it is, I want to write the file to that line. If not, I want to add it to the overflow area. Here's what I have:

while (Record.MySSN[[i][/i]i])
      Sum = Sum + (int) Record.MySSN [i++];
    Total = Sum % 99;
    Total = Total + 1;
    FirstCharacter[0] = OutputFile.peek();
    cout << FirstCharacter[0];

It gives me the correct Total of 69. If I print out "tellp()", it gives me 69. But, where I print out "FirstCharacter", I get a "Z", not a "*". I just want to check the first character without advancing the read/write arm. But, it gives me the Z instead of the *. Any suggestions to compare the first character on the line to a *? Thanks a lot.

<< moderator edit: added [code][/code] tags >>

13 Years
Discussion Span
Last Post by Tight_Coder_Ex

It appears the problem is not with the code but rather the calculation of the offset "Total" or the position you eventually end up at in the file. Maybe OutputFile.seekp(Total,ios::cur); would solve the problem. Without seeing the contents of your file and associated code in its entirety it's really difficult to tell.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.