I tried to implement Speller, but check 50 returns:
:( program is free of memory errors valgrind tests failed; rerun check50 with --log added to end of command for more information.
When I run valgrind it returns: ==20822== Invalid write of size 1 ==20822== at 0x422CD5: check (dictionary.c:98) ==20822== by 0x421373: main (speller.c:112)
Looks like you're trying to modify 1 byte of memory that isn't yours? Did you try to store something beyond the bounds of an array? Take a closer look at line 98 of dictionary.c.
My code:
// Returns true if word is in dictionary else false
bool check(const char *word)
{
// TODO
char *checkword = malloc(sizeof(LENGTH + 1));
// Make a copy of the word for lowercases
for (int i = 0; i < strlen(word) + 1; i++)
{
checkword[i] = tolower(word[i]); **<-----this is line 98**
}
// Get the pointer from the hashtable
int y;
y = hash(word);
node *cursor = hashtable[y];
while (cursor != NULL)
{
// Compare strings
if (strcmp(checkword, cursor->word) == 0)
{
free(checkword);
return true;
}
// If not the same word, go further down the linked-list
cursor = cursor->next;
}
free(checkword);
return false;
}
This is the first problem with the memory and I am thankful for any suggestions!