Array of Structures

This is a discussion on Array of Structures within the C Programming forums, part of the General Programming Boards category; How would you store information read from a file into an array where each element is a structure?...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Montreal, QC
    Posts
    6

    Array of Structures

    How would you store information read from a file into an array where each element is a structure?

  2. #2
    Registered User dariyoosh's Avatar
    Join Date
    Nov 2012
    Location
    Iran / France
    Posts
    33
    It depends on the format of the file: TXT, CSV, XML, HTML, etc. As I understand, obviously first you open the file for reading
    C File I/O Tutorial - Cprogramming.com

    And then you will need to define a function that takes each line and based on some delimiter (, or ; or | or simply space, etc), splits each line into separate tokens, each token corresponding to a field of your structure. This is done inside a loop reading each line of the file. During each iteration you have a local variable of the specific structure type whose fields are populated, at the end of the loop, this local element is added to your array.

    Regards,
    Dariyoosh

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of pointers to an array of structures
    By phoneix_hallows in forum C Programming
    Replies: 3
    Last Post: 08-27-2009, 11:13 AM
  2. array of structures
    By tish in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 06:52 AM
  3. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  4. 2 Dimenstional Array vs Array of Structures
    By jrahhali in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2004, 04:51 AM
  5. Array of Structures
    By TeenyTig in forum C Programming
    Replies: 1
    Last Post: 02-17-2002, 08:34 PM

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