When I run my program, the program output every single word in the text instead of solely misspelled words. I'm fairly confident the problem lies within my load function. Can someone identify anything wrong with my logic? Thank you!
bool load(const char *dictionary) { // TODO FILE *fp = fopen(dictionary, "r"); if (fp == NULL) { printf("Could not open %s.\n", dictionary); unload(); return 1; }
node root = {false,{NULL}};
node *ptr = &root;
for (int c = fgetc(fp); c != EOF; c = fgetc(fp))
{
if (isalpha(c))
{
if (ptr->children[c - 97] == NULL)
{
node *new = malloc(sizeof(node));
*new = (node) {false,{NULL}};
ptr->children[c - 97] = new;
ptr = new;
}
else
{
ptr = ptr->children[c - 97];
}
}
else if (c + '0' == '\n')
{
ptr->end_word = true;
ptr = &root;
}
}
fclose(fp);
return true;
}