Thread: Array of Structures

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

    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
    Iran / France
    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 -

    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.


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, 09:34 PM