Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Load from File into Arrays
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rar




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: