Thread: Filling Array Of Structures From A File

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    43

    Filling Array Of Structures From A File

    I'm having a hard time discovering how to fill an array of structures from a file. This is what I'm trying to do.

    I am going to open a file from the command line. In the file are a bunch of records some of them in the proper format and some not. Each of the records are on one line of the file, like this.

    Sumpter, David: 12445: 100: 85: 70: 78: B+
    Laporte, Leo: 23855: 88:88: 100: 76: B
    .
    .
    .
    ...and so on

    Any ideas how I can get this type of data into an array of structures dynamically?

    I don't need to handle all the records in the file just the first 100 valid records.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    What's the question, exactly? How to determine whether a line of data is valid, or how to use = to assign bits to a structure, or what?

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    43
    I have a file with a bunch of records in it. From the file I need to fill an array of structures. I have to do this dynamically.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by mesmer View Post
    I have a file with a bunch of records in it. From the file I need to fill an array of structures. I have to do this dynamically.
    Then do so. (Note that if you only care about the first 100, the word dynamic is in question, as you really just need an array of 100 structures.)

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    How dynamic do you need to be? There can be an efficiency issue here. I would start out by creating perhaps 100 structures and then fill them from there if you need more then allocate another block of 100. Allocating for each recored would be time consuming and much work of the CPU.

    What has been done so far as client code or implementation?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. filling an array with a simple file
    By arya6000 in forum C Programming
    Replies: 5
    Last Post: 11-25-2007, 01:34 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. array of structures, data from file
    By nomi in forum C Programming
    Replies: 5
    Last Post: 01-11-2004, 01:42 PM