C question explain please..
Hi I really need some serious help on what exactly I need to do, I am ment to make some codes in C but cant get my head round it, could someone please either explain parts of this to me or give me a scope of code of what I have to do. Any comment is welcomed.. Thanks. :eek:
The programs demonstrate the use of low-level file handling system calls. You must write a set of programs which provide a scoring facility for a game of darts. The first player to reach a score of exactly 250 will be deemed the winner. The program should support 5 players (though a game might involve as few as 2 players).
The scores will be stored in a file of 5 integer numbers, each representing the score of the corresponding player. You must therefore write an initial program to create and initialize this file. This program should:
accept the file name from the command line
create the file with RW permissions for owner
populate it entirely with zeroes (of which there should be 5, one for each player)
print out the file's inode number and size in bytes once it has created it
You must then write a program that records the scores. Note that the quality of user interface is not an important factor, so it is recommended that it is kept simple. The program should be passed the number of players for the game via the command line (acceptable range is 2 to 5). The program should allow two operations:
a New Game can be started, which resets all scores to zero
all current scores can be displayed
a score can be entered
If entering a score is chosen, the player number next in turn (so, it will be 1 to start off) is displayed (and also used as an index into the file), and then the score read in. The program should:
read the currently stored score for that player
add the new score to that value
if the new score is less than 250, write it to the file
if the new score equals 250, declare that player the winner, and print out the scores of all other players
if the new score exceeds 250, leave the file unmodified and tell the player the exact score needed to win
Finally, once you have these programs working, the final part of the exercise is to extend the functionality by adding a facility to record the names of the players, in addition to their scores.
The names should be stored in a separate file, where each element is a string (allow 20 characters for each) allowing a name to be stored. The files can be regarded as parallel arrays: the third position, say, in the scores file stores the score of the third player, whose name will be stored in the third string in the corresponding names file.
Thus the files might look something like this (assuming 2 players):
67 <-fds Sean <-fdn
and each file would have an associated file descriptor (fds and fdn in the example above) which could be manipulated according to a common method (eg moving the file pointer with lseek to "2 * sizeof(file_element_type)" from start of file would result in it pointing to the third score/name).
You will need to amend each of the programs (make a copy and amend that, not the original) so that:
the first program creates an additional file of empty strings
the second program:
prompts the user for the names of the players and stores them in the file
if the current scores option is chosen, prints out the names of players as well as their current score