my implementation of dictionary.c passes all checks using check50 except memory leaks. I'm using valgrind and most of my leaks seem to be happening in my check function:
// Returns true if word is in dictionary else false
bool check(const char* word)
{
// TODO
bool result = false;
char* tmp = malloc(sizeof(word) + 1);
strcpy(tmp, word);
for (int i = 0; i < strlen(tmp); i++)
{
tmp[i] = tolower(tmp[i]);
}
int index = hash(tmp);
node* n = arr[index];
while (n != NULL)
{
if (strcmp(n->w, tmp) == 0)
{
result = true;
break;
}
n = n->next;
}
free(tmp);
return result;
}
The reason I am using tmp is because I can't use tolower on char* word because it's a constant.