So I've got all the functionality down for dictionary.c and there are no leaks. I'm still getting 1 error in valgrind.
==8654== Conditional jump or move depends on uninitialised value(s) ==8654== at 0x4C2E1D1: strcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==8654== by 0x40143B: load (dictionary.c:106) ==8654== by 0x400A4D: main (speller.c:45)
Here's the code.
while(!feof(dptr))
{
// allocates enough memory for a new node
node* new_node = malloc(sizeof(node));
//checks if there is enough memory
if(new_node == NULL)
{
printf("Not enough free memory\n");
return false;
}
fscanf(dptr, "%s", new_node -> word);
strcpy(new_word, new_node -> word);
//updates word count until the end of the file is reached
if(!feof(dptr))
wordcounter++;
unsigned int i = hash_it(new_word);
new_node -> next = hashtable[i];
hashtable[i] = new_node;
}
From searching on here I understand that this is because I haven't initialized new_node -> word in strcpy and my hash function. I thought it was initialized in this line.
node* new_node = malloc(sizeof(node));
Do I have to do something like:
new_node -> word = NULL;
Thanks for your time.