Can someone tell me why I get segmentation fault?
bool load(const char *dictionary)
{
FILE *fp = fopen(dictionary, "r");
if (fp == NULL)
{
return false;
}
char word[45];
while (fscanf(fp, "%s", word) != EOF)
{
node *current = root;
for (int i = 0, n = strlen(word); i < n; i++)
{
if (word[i] == '\'')
{
if (current -> leaves[26] == NULL)
{
node *new_node = malloc(sizeof(node));
current -> leaves[26] = new_node;
current = current -> leaves[26];
}
else
current = current -> leaves[26];
}
// I get segfault here
else if (current -> leaves[word[i] - 'a'] == NULL)
{
node *new_node = malloc(sizeof(node));
current -> leaves[word[i] - 'a'] = new_node;
current = new_node;
}
else
current = current -> leaves[word[i] - 'a'];
}
current -> is_word = true;
counter++;
}
return true;
}
Thanks for any help.