View Single Post
Old Feb 24th, 2008, 11:06 PM   #7
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 598
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Help with variable-length fields

That looks as if someone wrote out the file in binary mode using a structure
struct person
{
    char SSAN[9];
    char last_name[25];
    char first_name[15];
    char address[30];
   // etc. etc
};
now to write that out to the file
ofstream out("filename",ios::binary);
struct person John;
out.write(&John, sizeof(struct person));

You can read that in very quickly like this
struct person John;
ifstream in("filename", ios::binary);
in.read(&John, sizeof(struct person));

Note that you don't have to read/write each field one at a time, and you can quickly access any record in random order by simply seeking to the desired spot.

I see no advantage of converting that to a standard text file unless you want to view it by some standard text editor such as Notepad.

But if you still want to convert the file just write a simple console program that reads in old format and writes in new format. I've already given you some code to work with that reads with the old format. Should be fairly straight-forward for you to write the code to rewrite into the new format, assuming you have the basic knowledge about how to read/write files.

Just in case you need help with that too:
ofstream out("newfile");
struct person John;
out << John.SSAN << " " << John.last_name << " " << John.first_name <<
  // etc. etc all the rest of the fields
The above assumes no spaces in any of the fields. Address field will more than likely have spaces, so instead of separating the fields with a space as I did above you can use some other character, such as a tab or '\n'.
__________________
<<Freelance Programmer>> << Hobby Site>>
Ancient Dragon is offline   Reply With Quote