#include "../include/hash_table.h" #include #include #include void generate_word(char *buf, size_t len){ for(size_t i =0; i< len -1; i++){ buf[i]= 'a' + (rand() %26); } buf[len -1] = 0; } int main(int argc, char **argv){ if(argc != 3){ printf("Usage: \n"); return EXIT_FAILURE; } char *filename = argv[1]; uint32_t num_guesses = atol(argv[2]); const uint32_t tablesize = (1<<20); Hash_Table *ht = hash_table_new(tablesize, hash_fnv1, NULL, 0); FILE *fp = fopen(filename,"r"); char buffer[4096]; uint32_t numwords = 0; while(!feof(fp) && fgets(buffer, 4096, fp) != NULL){ buffer[strcspn(buffer,"\n\r")] = 0; char *new = malloc(strlen(buffer)+1); strcpy(new,buffer); hash_table_create(ht, new, new, 0); numwords ++; } fclose(fp); printf("Loaded %d words into the table.\n", numwords); hash_table_print(ht,0); uint32_t good_guesses =0; const int shortest = 3; const int longest = 15; for(uint32_t i =0; i