Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would suggest trying to prototype what you want first in a higher level language such as Python. The following python code does what you desire.</p> <p>You should be able to follow along with this code and find equivalent C methods to accomplish the same tasks. The most complicated part will probably be deciding how to store the player/score pairs (in Python is is trivial, but unfortunately C does not have dictionaries).</p> <pre><code># Equivalent to C/C++ include import sys # Create dictionary to store scores data = {} # Check for existence of scores files try: with open("data.txt", 'r'): pass except IOError: pass with open("data.txt", 'r') as fp: for line in fp: # Split line by ':' parts = line.split(':') # Check that there are two values (name, score) if len(parts) != 2: continue # Remove white-space (and store in temporary variables) name = parts[0].strip() score = parts[1].strip() # Store the name and score in dictionary data[name] = score # Get input from user update_name = raw_input('Enter player name: ') update_score = raw_input('Enter player score: ') # Update score of individual data[update_name] = update_score # Write data to file (and to screen) with open("data.txt", 'w') as fp: for name,score in data.items(): output = "{0} : {1}".format(name,score) print output fp.write(output + '\n') </code></pre> <p>A few tips:</p> <ul> <li><code>fscanf(file, "%s : %d", name, score)</code> to replace most of the <code>split</code> and <code>strip</code> code.</li> <li><code>struct { char* e_name; int e_score; } entry;</code></li> <li>Take a look at this answer for arrays of structs <a href="https://stackoverflow.com/a/260981/2372604">https://stackoverflow.com/a/260981/2372604</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload