CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jan 2003
    Location
    The Volunteer State - USA
    Posts
    90

    How to locate a record

    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
    --------------------------------------------
    http://www.volfirst.net/~sirjorj/index.html
    ---------------------------------------------

  2. #2
    Join Date
    Nov 2003
    Posts
    74
    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.

  3. #3
    Join Date
    Jan 2003
    Location
    The Volunteer State - USA
    Posts
    90
    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.
    --------------------------------------------
    http://www.volfirst.net/~sirjorj/index.html
    ---------------------------------------------

  4. #4
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222
    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
    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.
    Last edited by bluesource; January 22nd, 2004 at 03:06 PM.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637
    Do you need to do this find repeatedly, or just once? How big is the text file?

  6. #6
    Join Date
    Sep 2002
    Posts
    9
    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

  7. #7
    Join Date
    Jan 2004
    Posts
    12
    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.

  8. #8
    Join Date
    Jan 2003
    Location
    The Volunteer State - USA
    Posts
    90
    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.
    Last edited by Sirjorj; January 23rd, 2004 at 09:37 AM.
    --------------------------------------------
    http://www.volfirst.net/~sirjorj/index.html
    ---------------------------------------------

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637
    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.
    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.

  10. #10
    Join Date
    May 2002
    Posts
    511
    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.

  11. #11
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637
    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.
    Variable length strings.

  12. #12
    Join Date
    Jan 2003
    Location
    The Volunteer State - USA
    Posts
    90
    Thanks all,
    You have given me some ideas to pursue.
    --------------------------------------------
    http://www.volfirst.net/~sirjorj/index.html
    ---------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured