i am confused on something...
i have made a hash file, now how do i use the key to search it?
i am confused on something...
i have made a hash file, now how do i use the key to search it?
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.
it is a binary file?? does that help?
the binary hash file is composed of 60 byte structs. how can i search such a file with NAME as the key?
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; }
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?