I have the dictionary loaded, and the first part of check done but -
- I cannot move the cursor properly.
- strcmp is not working properly. I tested it alone in another file and it did work. It is just not here.
It is in the block near the bottom that I think the problem is, moving through the list.
if(strcmp(arr, head->word) == 0)
{
puts("equal");
return 0;
}
//try to set the cursor to it's own next value (not sure if U can do this?)
1. cursor = cursor->next;
OR
//keep moving head and pointer cursor to head ->next
2. cursor = head -> next
//reset head to 2nd node, and so on
head = cursor;
Both of the two attempts to move the cursor print out the same values.
The dictionary prints fine with ethier syntax
printf("dictionary word:%s\n",cursor->word)
But the text is not working. It prints each word multiple times. Like 100x each. No idea why.
printf("text word:%s", arr)
Check() function
#include "dictionary.h"
int hashValue(const char *word);
typedef struct node
{
char word[LENGTH + 1];
struct node *next;
}
node;
node *hash_table[HASHTABLE_SIZE] = {NULL};
// Returns true if word is in dictionary else false
bool check(const char *word)
{
char arr[LENGTH+1];
// HASH VALUE
// hash to get bucket/array index
int hash_index = hashValue(word);
// set head to first node in bucket/array
node *head = hash_table[hash_index];
// SET WORD TO LOWER
for(int i = 0; i < strlen(word);i++)
{
arr[i] = tolower(word[i]);
}
// printf("string: %s\n", arr);
// set cursor originally to head
node *cursor = head;
while(cursor != NULL)
{
if(strcmp(arr, head->word) == 0)
{
puts("equal");
return 0;
}
cursor = head->next;
printf("%s\n", arr);
head = cursor;
}
return true;
}
Full file with load() if this if needed https://gist.github.com/chrisdel101/f34af62bd75454fe8511ec3750498556