Thread: Bowling again.

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

    Bowling again.

    I've noticed a previous thread about the same assignment I'm doing, but I'm asking a different question.

    Here is the bowling.dat file:
    Homer Simpson
    0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 -1
    Marge Simpson
    3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -1
    Lisa Simpson
    4 6 3 7 2 8 1 9 3 7 3 7 2 8 1 9 0 10 9 0 -1
    Bart Simpson
    4 6 3 7 2 8 1 9 3 7 3 7 2 8 1 9 0 10 9 1 9 -1
    Krusty the Clown
    0 0 0 0 10 1 1 0 0 0 0 0 0 0 0 0 0 0 0 -1
    Apu Nahasapeemapetilon
    8 1 7 1 5 2 6 2 9 1 5 4 4 5 2 3 6 3 4 2 -1
    Ned Flanders
    10 5 5 6 0 10 0 2 0 1 4 5 4 6 7 3 10 10 10 -1
    Barney Gumble
    10 10 10 10 10 10 10 10 10 10 10 10 -1
    Grampa Simpson
    0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 0 1 -1
    End of data


    I'm not asking for the entire code, just come guidance. With the program I'm using (quincy), I've opened up the file, and now I have no idea how to read ONLY the name and how to stick it into a string. I've been told to create a function to read the names, but I'm completely clueless? Any advice?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    you will have to actually read all the lines sequentially from beginning of the file to end of the file. Since the name appears consistently on every other line, that is all you have to keep in the program -- you can just toss the others into the bit bucket.

    use fopen() to open the file in text mode, and fgets() to read each line. I suspect the function should copy the names into some sort of character array so that the calling function can use them for something. Generally you would want to use a linked list, but that's probably beyone the scope of your assignment. Just have the calling function create a 2d array and pass it to the function that reads the array.

    Code:
    void read_names(char names[10][])
    {
      // blabla
    }
    
    int main()
    {
       char names[10][40];
    
       read_names(names);
    }

  3. #3
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Quote Originally Posted by Ancient Dragon
    Code:
    void read_names(char names[10][])
    void read_names(char names[][40])
    {
      // blabla
    }
    
    int main()
    {
       char names[10][40];
    
       read_names(names);
    }
    When declaring a function taking a two dimensional array, the rightmost value must be specified, so that the function knows the offsets of the elements.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Oops!

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Sure, just copy your buddy's excellent code.
    http://cboard.cprogramming.com/showthread.php?t=72763

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a bowling program...
    By fuze in forum C++ Programming
    Replies: 2
    Last Post: 01-11-2008, 04:06 AM
  2. bowling games in c
    By zarith in forum C Programming
    Replies: 2
    Last Post: 10-09-2007, 06:41 AM
  3. Help required! Bowling Assignment.
    By Pacino in forum C Programming
    Replies: 22
    Last Post: 12-08-2005, 12:55 PM
  4. A Different Bowling Program
    By Mike56p in forum C Programming
    Replies: 3
    Last Post: 12-08-2005, 09:47 AM
  5. Need Help with a Bowling Score Program
    By oobootsy1 in forum C++ Programming
    Replies: 6
    Last Post: 11-01-2005, 10:04 AM