This is my code for load and valgrind points at line 127 as the reason for the seg. falut. Please, can someone point out to me why. Thanks.`/** *Loads dictionary into memory. Returns true if successful else false **/ void initialize(node* currentNode) { currentNode ->is_word = false; for(int k = 0; k < 27; k++) { currentNode ->children[k] = NULL; } }
bool load(const char dictionary)
{
root = NULL;
node newNode = NULL;
//point root to the travasal node: currentNode
//create root node
root = calloc (1, sizeof(node));
currentNode = root;
//open dictionary file & check if it's null
inptr = fopen (dictionary, "r");
if (inptr == NULL)
{
return false;
printf ("Could not open dictionary\n");
fclose(inptr);
}
for (letter = fgetc(inptr); letter != EOF; letter = fgetc(inptr))
{
if (isalpha (letter))
{
tolower(letter);
indes = (letter - 'a');
}
if (letter == '\'')
{
indes = 26;
}
currentNode = currentNode -> children[indes];
//if currentNode is null, malloc newnode
if (currentNode -> children[indes] == NULL)
{
newNode = calloc (1, sizeof(node));
currentNode = newNode;
}
currentNode = currentNode -> children[indes];
if (currentNode -> is_word == true && letter == '\n')
{
word_count++;
}
currentNode = root;
}
fclose(inptr);
`