Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 24th, 2008, 3:27 PM   #1
starbeam
Newbie
 
Join Date: Jan 2008
Posts: 10
Rep Power: 0 starbeam is on a distinguished road
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.
starbeam is offline   Reply With Quote
Old Feb 24th, 2008, 3:29 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Re: Help with variable-length fields

You're going to have to rephrase that question so it actually makes sense.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 24th, 2008, 3:33 PM   #3
starbeam
Newbie
 
Join Date: Jan 2008
Posts: 10
Rep Power: 0 starbeam is on a distinguished road
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.
starbeam is offline   Reply With Quote
Old Feb 24th, 2008, 4:24 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 24th, 2008, 5:48 PM   #5
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 499
Rep Power: 4 Ancient Dragon is on a distinguished road
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.
Ancient Dragon is offline   Reply With Quote
Old Feb 24th, 2008, 9:39 PM   #6
starbeam
Newbie
 
Join Date: Jan 2008
Posts: 10
Rep Power: 0 starbeam is on a distinguished road
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
starbeam is offline   Reply With Quote
Old Feb 24th, 2008, 10:06 PM   #7
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 499
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'.
__________________
I Like Ike. Vote for Dwight Eisenhower this November.
--This message brought to you by the the Procrastinators Club Of America.
Ancient Dragon is offline   Reply With Quote
Old Feb 24th, 2008, 10:52 PM   #8
starbeam
Newbie
 
Join Date: Jan 2008
Posts: 10
Rep Power: 0 starbeam is on a distinguished road
Re: Help with variable-length fields

thanks that helped a lot!
starbeam is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC