![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2008
Posts: 10
Rep Power: 0
![]() |
Help with variable-length fields
Anyone know where I can get a program that will make use of variable-length fields and variable-length records and convert a file to using variable length.
|
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Re: Help with variable-length fields
You're going to have to rephrase that question so it actually makes sense.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2008
Posts: 10
Rep Power: 0
![]() |
Re: Help with variable-length fields
Okay so say I there is a program that generated a file but it is in fixed length records. How would I go about writting a program that changes a file into using variable lenght fields and variable lenght records.
|
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Re: Help with variable-length fields
Starting to make more sense. What do you mean by "fixed-length records?" Can you give me an example of what you have currently and what you'd like it to be after you change it?
|
|
|
|
|
|
#5 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 532
Rep Power: 4
![]() |
Re: Help with variable-length fields
Nothing wrong with using fixed-length records, they actually have a lot of advantages over variable length records. Do the fixed-length records contain binary data and you want to convert them to readable text data? If that's the case then you can fairly easily write a conversion program that reads the fixed length records and rewrites them as variable length records into a different file. I've done it several times and it pretty simple stuff, providing you know the format of the fixed length binary records.
__________________
I Like Ike. Vote for Dwight Eisenhower this November. --This message brought to you by the the Procrastinators Club Of America. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Jan 2008
Posts: 10
Rep Power: 0
![]() |
Re: Help with variable-length fields
Okay so you have info like for example this....
Field/ Name/ Fixed length 1/ SS#/ 9 2/ Last Name/ 25 3/ First Name / 15 4/ Address / 30 5/ City / 25 6/ State code / 2 7/ Zip code / 5 8/ # courses / 2 But some of the things do not need to be fixed length. Others are fine that way but some would be better as variable length |
|
|
|
|
|
#7 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 532
Rep Power: 4
![]() |
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
};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
__________________
I Like Ike. Vote for Dwight Eisenhower this November. --This message brought to you by the the Procrastinators Club Of America. |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jan 2008
Posts: 10
Rep Power: 0
![]() |
Re: Help with variable-length fields
thanks that helped a lot!
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Putting spaces between formatted text fields | Fall Back Son | Java | 7 | Feb 12th, 2008 8:40 PM |
| Correct name for a variable length loop? | funkey_monkey | Other Programming Languages | 6 | Jun 2nd, 2007 12:50 AM |
| Is this declaring a variable? | waveform | C++ | 21 | Jun 23rd, 2006 3:48 PM |
| How to force all form fields to be submitted | aznluvsmc | Perl | 4 | Oct 28th, 2005 6:30 PM |
| variable problem | robert_sun | C | 1 | Apr 12th, 2005 2:10 PM |