The numbers in the text file where like this:How did you do it ?
1|2|3|4|5|6|7|8|9|10
To extract a number I used:
HighScoresfile.getline(buf1, 1024, "|");
buf1 was a char array with 1024 places.
Then I copied the contents of the array into an int called HS1:
HS1 = atoi(buf1);
Then I repeated the it, only with the buf and HS number increasing until it got to 10.
I have feeling that this is not the best way to do it, but we have not been taught how to do stuff with files yet. It works, so I am pleased with myself.
We will probably be doing this stuff next year.Ultimately, I think you'll want to use something other than a text file for this application. A text file will do the job, but as you get more programming knowledge you'll be able to use:
1. A binary file containing records (I think this is what most games do)
2. A database of some kind, such as MySQL
Bookmarks