binary file into class using dynamic arrays

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2007
Posts: 2
Reputation: amorphis_gr is an unknown quantity at this point 
Solved Threads: 0
amorphis_gr amorphis_gr is offline Offline
Newbie Poster

binary file into class using dynamic arrays

 
0
  #1
Oct 11th, 2007
i hace a class in c++ bcw
  1. class Student {
  2. public:
  3.  
  4. private:
  5. unsigned int sIdNum;
  6. char sSurname[20];
  7. char sFirstname[20];
  8. char mathid[10];
  9. };//Student

i need a function that fills a Student type dynamic array from a bin file called binfile1.dta the array starts with size[30]. And then do the same for another file binfile2.dta to fill a dynamic array student type char mathid[10] the array starts with size[5].when an array wants more memory it must renew it self and ask more space.

can anybody help me ?

the binfile1.dta has data for sIdNum,sSurname,sFirstname
the binfile2.dta has data for mathid (math id is like XX000 XX001 etc in lines )
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,728
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 737
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: binary file into class using dynamic arrays

 
0
  #2
Oct 11th, 2007
>can anybody help me ?
If by "help" you mean "write it for me", no. Nobody will help you. If you mean help in the more traditional sense of you do the majority of the work and we give you hints and tips, and suggest ways to improve your solution, yes. We'll be happy to help. But as it is, you don't have any code and haven't told us how you plan to write this function, so there's nothing to help with.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,440
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1473
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: binary file into class using dynamic arrays

 
0
  #3
Oct 11th, 2007
>>mathid[10] the array starts with size[5].when an array wants more memory it must renew it self and ask more space.

You can't dynamically expand the array size when it is statically allocated like you posted in the class. You will have to make mathid a pointer if you want to change its size at runtime.

Or better yet, since this is a c++ program using std::string instead of character arrays. The string class will do all the messary memory allocations for you, simplifying your whole program.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 2
Reputation: amorphis_gr is an unknown quantity at this point 
Solved Threads: 0
amorphis_gr amorphis_gr is offline Offline
Newbie Poster

Re: binary file into class using dynamic arrays

 
0
  #4
Oct 11th, 2007
.
Last edited by amorphis_gr; Oct 11th, 2007 at 9:55 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,440
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1473
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: binary file into class using dynamic arrays

 
0
  #5
Oct 11th, 2007
If that file contains variable length strings then you can not read it with just one read statement. You will have to devise a more complex algorithm to read the file. Exactly what algorithm depends on the file's contents, that is, how was that file written.
Last edited by Ancient Dragon; Oct 11th, 2007 at 9:42 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC