Computer Science Canada

Load from File into Arrays

Author:  rar [ Sun Mar 14, 2010 7:16 pm ]
Post subject:  Load from File into Arrays

So I'm working with the same program as in my other "Manipulating Structures" thread.

I'm trying to load the information from a file into an array. So say the file is "contacts.txt". The file will read something like:

Contact #1:
First name: John
Last name: Smith
Address: 854 Elm Street
Postal Code: F8F-9F4
Phone Number: (485) 495-4958

So I essentially want to load the name, address, etc. into the array that I use in the program. How might I do this?

Author:  Insectoid [ Sun Mar 14, 2010 9:45 pm ]
Post subject:  RE:Load from File into Arrays

You have a 'contact' object? I don't know how to do it in C, but it should work like this


until end_of_file {
exampleContact.new
contact.number = file.getline
contact.firstName = file.getline
....

arrayOfContacts.push (exampleContact)
}

you could do this with parallel array but that's messy.


: