Please Help with Searching

This is a discussion on Please Help with Searching within the C++ Programming forums, part of the General Programming Boards category; i am confused on something... i have made a hash file, now how do i use the key to search ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    64

    Smile Please Help with Searching

    i am confused on something...
    i have made a hash file, now how do i use the key to search it?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    What does your hash table look like? An array of linked lists? Then use the hashvalue of the object your searching for to get the proper array element, then do a linear search through that linked list.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    64
    it is a binary file?? does that help?

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    64
    the binary hash file is composed of 60 byte structs. how can i search such a file with NAME as the key?

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    66
    A hash file? That's weird, but you can try using fseek, I'm not sure, but this works for me.
    Code:
    #include <stdio.h>
    
    int main( )
    {
        FILE *fp;
        char rec[100]; // Record size is 100
        if(fp = fopen("records.txt", "rb"))
        {
            int read;
            int record = 1;
            fseek(fp, record * 100, SEEK_SET); // Go to the second record
            read = fread(rec, 1, 100, fp);
            if(read)
            {
                rec[read] = 0;
                printf("%s\n", rec);
            }
        }
        return 0;
    }

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    64
    I am not sure if that will work? Maybe someone else can help more with fseek?? is that used for searching quickly based on the KEY?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 06:20 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  4. Searching and matching strings: segmentation fault
    By Smola in forum C Programming
    Replies: 18
    Last Post: 07-11-2005, 01:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21