I am reading from a file 3 things, name, street, and address. And I want to put it in a hash table with 6 buckets for easy access. I searched around and got some code which started me out. but now i have no idea how to initilize and add 60 people into it. I understand that I must use some algorithim to turn the name into a key, but what do i do when i get the key?
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #define STRINGBUF 1000 #define BUCKETNUM 6 typedef struct tperson{ char name[STRINGBUF]; char address[STRINGBUF]; int key; struct tperson *next; }person; //function declarations void ReadList(void); void InitHash(void); void HashFunction(void); void PrintHashTable(void); int main(){ return 0; } void InitHash(){ } void HashFunction(){ } void PrintHashTable(){ } void ReadList(){ FILE *filelist; filelist=fopen("fileit.txt", "r"); char line[STRINGBUF]; char *name,*street,*city; while(fgets(line, sizeof(line), filelist)!=NULL){ name=strtok(line,";"); street=strtok(NULL,";"); city=strtok(NULL,";"); } fclose(filelist); }



LinkBack URL
About LinkBacks


