Help with sorting a .dat file

Hello. I'm new here.
I'm learning C++ at school. However, our school board enforces us to use TC(Turbo C++), so I'm stuck with this primitive excuse of a compiler. Anyway, I decided to make a game using graphics, and have made a LOT of progress.



I have encountered a problem, however. I'm trying to store the score and the name of the player after he has succesfully completed the level. I use this function receive the name and store the score in a class.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  void store(int score1)
{
cleardevice();
a.score=score1;
drawbrickborder();
gotoxy(8,8);
cout<<"Congratulations on finishing the game!";
delay(1000);
cout<<"\nEnter your name:";
cin>>a.name;

ofstream etho;

etho.open("High.dat",ios::in|ios::binary|ios::app);
etho.write((char*)&a,sizeof(a));

cout<<"Hit any key to continue";
getch();
highscore();

cleardevice();
menu();


Next, I attempt to make a function whose desired output is to display the top 5 scores in tha .dat file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
void highscore()
{
 data b;
 cleardevice();
 drawbrickborder();
 fstream bdubs;
 bdubs.open("High.dat",ios::in|ios::binary);
 int big=0,pos[5]={-1,-1,-1,-1,-1},i=0;
 bdubs.seekp(0);

 while(i<5)
 {
  while(!bdubs.eof())

  {
   bdubs.read((char*)&b,sizeof(b));
      for(int j=0;j<5;++j)
      if(pos[j]==bdubs.tellg())
      goto end;

   if(b.score>big)
   {
    pos[i]=bdubs.tellg();
    big=b.score;
   }

   end:

  }
  ++i;
 }



 gotoxy(6,6);cout<<"High Scores";
 for(int j=0;j<5;++j)
 {
  if(pos[j]==-1)
  break;
  bdubs.seekp(pos[j]);
  bdubs.read((char*)&b,sizeof(b));
  cout<<"\n"<<b.name<<"\t"<<b.score;
 }

 getch();
 cleardevice();
 menu();


}


Basically, I'm storing the positions of the five largest score values in the .dat file, then displaying them in descending order.


The first time I ran my code, I saw the score, and my name, under High scores.
However, the second time onwards, the list did not get updated, and I kept seeing the same score and name over and over.

To understand what was going on, I deleted the .dat file. However, from then on, only junk values have been turning up in my high score display.

Any suggestions?
Is my algorithm to sort the .dat file right?
Thanks a lot for your answers, I look forward to being an active part of this community after I'm done with school.
*bump*
Topic archived. No new replies allowed.