LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to manage high score file

Hello,

I have made i little game in CVI, in the end of the game user get a score base on the levels he passed and the level of difficulty.

As this is a school assignment i have to have a score board. I've made score board using a table and i read arguments from a txt file.

All I read is the name of the player and his score.

The trouble that I'm having is to check the txt file and see if the new score of the user can be put in the score board.

I need to known how I check if user's new score need to be put into the score txt file, and how to put it there.

 

Thanks in advacne!

0 Kudos
Message 1 of 2
(4,140 Views)

Hello Slavik87!

 

If I understand your question correctly, want to are asking is how to read the text file, retrieve the highest scores from it and update the file again.

If you are asking about which functions to use, these are some functions you can use to perform the file operations:

  • fopen, to open the file
  • fputs, to write a string to the file
  • fgets, to get a string from the file
  • fseek, to navigate through the file
  • fclose, to close the file

Here are some suggestions about how you can manage the information in your text file:

  • Insert each new entry (name, score) on a separate new row, optionally using separators:
    John Doe, 10
    Kelly Smith, 43
    Kevin Brown, 4
  • After reading these lines from disk, you would have to store the entries in some data structures (e.g. lists, structures) for your application to manage.
  • For optimization, you can also sort the rows based on the highest score, this way, when you want to retrieve the highest scores, these are already situated at the beginning of the file. However, when you update the rows, you would have to switch places of rows, when a person will have a higher score than the previous item(s).

Best regards!

- Johannes

0 Kudos
Message 2 of 2
(4,129 Views)