i keep getting segmentation fault when running this code. using printf i can see its from loading ala and the hashtable to store this is set to nil. other words when the hashtable to store them is nil are loaded. can someone explain why this is happening.
// Loads dictionary into memory, returning true if successful, else false
bool load(const char *dictionary)
{
// TODO
for (int i = 0; i < 18000; i++)
{
table[i] = NULL;
}
FILE *file = fopen(dictionary, "r");
char text[LENGTH];
char c;
int textchar = 0;
int hashtotal = 0;
while (fread(&c, sizeof(char), 1, file))
{
text[textchar] = c;
textchar++;
if (c == '\n')
{
node *n = malloc(sizeof(node));
if (n == NULL)
{
return false;
}
hashtotal = hash(text);
n->next = table[hashtotal];
strcpy(n->word, text);
printf("%p\n", table[hashtotal]);
table[hashtotal] = n;
wordcount++;
textchar = 0;
for (int i = 0; i < LENGTH; i++)
{
text[i] = 0;
}
}
}
return true;
}