Files, Structs, and Pointers
Hi, what I'm doing is reading in information from a binary file, and storing that information into an array of structs. Here is that bit of code. Record in this case is my base struct.
Code:
int read_file( int filesize , int &count , Record *&ptr , fstream &file )
{
int i = 0;
file.seekg(0,ios::end); // move to end of file
filesize = file.tellg(); // get number of byte in file
count = filesize / sizeof(Record); // compute number of records
file.seekg(0,ios::beg); // move to beginning of file
ptr = new Record[count];
for( i = 0 ; i < count ; i++ )
{
file.read( (char *) &ptr[i] , sizeof(Record) );
}
return count;
}
Once the entire binary file is read in, I no longer use the file until I am going to write to it. So in the run of the program I do all my messing around with the information within the structs after they are stored in this array.
This is probably a simple question, but how do I allocate more space for new structs in this array? During the run of the program, I will be adding and deleting records, and as my code stands I only have enough room for what I read in originally, correct?
After manipulating the info, it is all written back into the file.
Thanks for any help. ;)