C question explain please..

This is a discussion on C question explain please.. within the C Programming forums, part of the General Programming Boards category; Hi I really need some serious help on what exactly I need to do, I am ment to make some ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    4

    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.



    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):


    scores_file names_file

    96 Paul
    67 <-fds Sean <-fdn
    0 -
    0 -
    0 -


    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

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Have you tried to write the code yet? If so, post your attempt[s].
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    The programs demonstrate the use of low-level file handling system calls
    What functions are those: fopen() and associated FILE* functions, or the even lower-level open(), read(), write() etc?

    I think you need to not get overwhelmed with all those requirements. Start at the top and code one requirement at a time. For example.
    accept the file name from the command line
    Code:
    #include <stdio.h>
    #include <io.h>
    
    int main(int argc, char* argv[])
    {
       char* filename = NULL;
       if( argc == 2)
           filename = argv[1];
       else
       {
           printf("Error\n");
           return 1;
       }
    
       
    
       return 0;
    }
    Now once that is working, you can go on to the next requirement. I'll leave the rest up to you.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    See comments here.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. can anyone explain this question for me?
    By MyRedz in forum C++ Programming
    Replies: 4
    Last Post: 02-05-2009, 05:30 AM
  3. One Easy" C " Question. Please Solve and Explain.
    By RahulDhanpat in forum C Programming
    Replies: 18
    Last Post: 03-24-2008, 01:39 PM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM
  5. question once again..
    By sunnycyboid in forum C Programming
    Replies: 1
    Last Post: 11-08-2002, 03:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21