I have a very large text file containing records that consist of a NULL terminated Name (vartiable length) followed by an Int. I need a routine which will find a particular record for a given name.
What would be a good way to accomplish this?
TIA:)
Printable View
I have a very large text file containing records that consist of a NULL terminated Name (vartiable length) followed by an Int. I need a routine which will find a particular record for a given name.
What would be a good way to accomplish this?
TIA:)
Create an ADO recordset, read in and parse the file and put the data into the recordset fields. You can then do a find call and find any specific row of data you need.
Thank you Adam for your reply. However, I'm not concerned with a DataBase Management program and I'm not familiar with ADO and was hoping for a simpler approach. The records, I might add, are already sorted on Name. Another approach would be appreciated. :D
Perhaps you could just create a search routine which reads each line in the file then performs a check on the line. You can parse the line so that it separates the name and number as needed.Quote:
I have a very large text file containing records that consist of a NULL terminated Name (vartiable length) followed by an Int. I need a routine which will find a particular record for a given name.
What would be a good way to accomplish this?
TIA
Do you need to do this find repeatedly, or just once? How big is the text file?
See the following for an efficient string search algorithm:
Boore - Moore Search
You'll probably have to make modifications since you indicated that you have 'ints' in your file -- it uses strlen functions and you'd probably get premature returns
make HASH code for each record in you file (index file)
story codes in separate file (or in some)
and add to code offset value of record from start of file
to find record all you need is find it HASH code in table
and you get offset in file.
In answer to GCDEF's question- This would be a one-time thing.
I need the number that is associated with each name then the source file is scrap. And, Oh yes, the size of the source file is 120k byts.
Well, 120K isn't that big. If you only need to do it once, it doesn't need to be particularly effecient. I'd just read it into a large char array and look for the value you want.Quote:
Originally posted by Sirjorj
In answer to GCDEF's question- This would be a one-time thing.
I need the number that is associated with each name then the source file is scrap. And, Oh yes, the size of the source file is 120k byts.
You can read the entire file in and since the records are sorted you can do a simple binary search using bsearch() to speed up your search.
Variable length strings.Quote:
Originally posted by Tron
You can read the entire file in and since the records are sorted you can do a simple binary search using bsearch() to speed up your search.
Thanks all,
You have given me some ideas to pursue.
:wave: