I have been beating my head against a wall trying to solve my issues on my own, but I have gotten no where. I have two issues: 1) I have a small memory leak of 568 bytes in 1 block. My unload function seems to work properly aside from this if the program can get that far, which brings me to 2) I have some form of error occuring with my call for strcmp() saying "Conditional jump or move depends on uninitialised value(s)" and "Uninitialised value was created by a stack allocation". If I run my code with a small dictionary and text file the program will run to completion and return the proper counts for misspelled words, words in dictionary and words in text. The memory leak is the same regardless of sizes. If I try to use the full dictionary with a longer text the program crashes with literally millions of errors. I think that my stack is overflowing, but I cannot figure out why or how to fix it. Below are the chunks of code in question. Please keep in mind, I am very new to computer science so any feedback or pointers to write better code would also be greatly appreciated.
bool check(const char *word)
{
int b = 0;
char lword[strlen(word) + 1];
for (int y = 0; y < strlen(word); y++)
{
lword[y] = tolower(word[y]);
}
node *checker = head[lword[0] - 'a'];
while (checker != NULL)
{
if (strcmp(lword, checker -> word))
{
b = 1;
}
checker = checker -> next;
}
if (b == 1)
{
return true;
}
else
{
return false;
}
}
bool load(const char *dictionary)
{
FILE* fp = fopen(dictionary, "r");
if (fp == NULL)
{
return false;
}
char term[LENGTH + 1];
while (fscanf(fp, "%s", term) != EOF)
{
counter++;
node *new_node = malloc(sizeof(node));
if (new_node == NULL)
{
unload();
return false;
}
strcpy(new_node -> word, term);
int x = term[0] - 'a';
new_node -> next = head[x];
head[x] = new_node;
}
return true;
}
bool unload(void)
{
for ( int i = 0; i < 26; i++)
{
node *cursor = head[i];
while (cursor -> next != NULL)
{
node *temp = cursor;
cursor = cursor -> next;
free(temp);
}
free(cursor);
}
return true;
}