0

Not sure what's wrong, I've been staring at this for days. It will not load any dictionary.

    bool load(const char *dictionary)
{

FILE *f = fopen(dictionary, "r");
if (f == NULL);
{
    return false;
}

//root = calloc(1, sizeof(node));
//node* current;
//current = root;

while (!feof(f))
{
    char word[LENGTH+1]; // array to store word
    fscanf(f, "%s", word);
    count++;

    node *ptr = root;
    for (int i = 0, n = strlen(word); i<n; i++)
    {

        if (ptr-> children[nth(word[i])] == NULL)
        {

            node *new_node = malloc(sizeof(node));
            if (new_node == NULL)
            {
                unload();
                return false;
            }    
        }

        if (ptr->children[nth(word[i])] != NULL)
        {
            return true;
        }
    }
    ptr->is_word = true;
}


fclose(f);
return true;
}

1 Answer 1

1

If you're getting the "cannot load dictionaries/large" error, it sounds like it isn't a coding problem, it's a file location problem. For the default dictionary to load, it has to be named large, and must be in the dictionaries directory, which must be a directory in the current directory.

Another test is whether it can open a dictionary provided as a parameter. For example, can you run ./speller small small with small being a small dictionary in the current directory?

If this isn't the problem, please edit the question and add a description and examples of the errors that you are seeing.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • So I'm confused. You edited the question saying that it wouldn't load any dictionary, but you've accepted the answer. Does that mean you found the problem?
    – Cliff B
    Oct 6, 2016 at 21:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .