Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns true if word is in dictionary else false.
- */
- bool check(const char *word)
- {
- // copy const char to new variable (to lowercase it)
- char *low_case_word = malloc((strlen(word) + 1) * sizeof(char));
- strcpy(low_case_word, word);
- // convert word to lowercase
- for(int i = 0; i < strlen(word); i++)
- {
- low_case_word[i] = tolower(word[i]);
- }
- //check hash index of current word
- int hash_index = hash(low_case_word);
- return check_single_index(hashtabe_array[hash_index], low_case_word);
- }
- bool check_single_index(hash_table *table, char *low_case_word)
- {
- // create a temporary pointer for traveling across nodes
- hash_table *trav = table;
- // if word is not first in dictionary - go further
- while(trav != NULL)
- {
- // if current node includes word - return true
- if(strcmp(trav->word, low_case_word) == 0)
- {
- free(low_case_word);
- return true;
- }
- // go to next node
- trav = trav->next;
- }
- free(low_case_word);
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement