i have made some changes but it still prints all words as misspelled.can you please take a look at it??please
define HASHTABLE_SIZE 1346
include
include
include
include
include "dictionary.h"
typedef struct node { char word[LENGTH + 1]; struct node *next; } node;
node *hashtable[HASHTABLE_SIZE];
unsigned int hash(const char* word) { int sum = 0; for(int i=0; word[i] != '\0';i++)
sum=sum + tolower(word[i]);
return sum % HASHTABLE_SIZE;
} unsigned counter=0; /** * Returns true if word is in dictionary else false. */ bool check(const char *word) { char word2[LENGTH + 1] = {};
int size=strlen(word);
for(int i = 0;i < size;i++)
{
word2[i] = tolower(word[i]);
}
word2[size] = '\0';
int index1=hash(word2);
node *cursor = hashtable[index1];
while(cursor != NULL)
{
if(strcasecmp(word2,cursor->word)==0)
{
return true;
}
else
cursor = cursor->next;
}
return false;
} /** * Loads dictionary into memory. Returns true if successful else false. */
bool load(const char dictionary) { char word[LENGTH+1] = {}; FILE fp=fopen(dictionary,"r"); { if(fp == NULL) { fprintf(stderr,"couldnot open %s\n",dictionary); } while(fscanf(fp, "%s\n" , word) != EOF) { node* new_node=malloc(sizeof(node)); if(new_node == NULL) { unload(); return false; } strcpy(new_node -> word,word); int index=hash(new_node -> word);
if(hashtable[index] == NULL)
{
hashtable[index] = new_node;
new_node ->next=NULL;
counter++;
}
else if(hashtable[index] != NULL)
{
new_node ->next = hashtable[index];
hashtable[index] = new_node;
new_node ->next=NULL;
counter++;
}
}
}
fclose(fp);
return true; }