0

load function looks good I think the error in speller.c when I wrote ./speller texts/lalaland.txt output: MISSPELLED WORDS Could not unload dictionaries/large. when wrote ./speller text output: Could not open text. I also try to remove fclose in load function and no difference.

 bool load(const char *dictionary)
{
    node *n;
    char word[LENGTH + 1];
    int number;
    FILE *f = fopen(dictionary, "r");
    if (f == NULL)
    {
        return 1;
    }
    while (fscanf(f, "%s", word) != EOF)
    {
        dicSize++;
        n = malloc(sizeof(node));
        if (n == NULL)
        {
            return 1;
        }
        strcpy(n-> word, word);
        n->next = NULL;
        number = hash(word);
        if (table[number] == NULL)
        {
            table[number] = n;
        }
        else
        {
        n->next = table[number];
        table[number] = n;
        }
    }
    // for (int i = 0; i < 1; i++)
    // {
    //     for (node *j = table[i]; j != NULL; j = j->next)
    //     {
    //         printf("the word: %s\n", j->word);
    //     }
    // }
    dicSize = true;
    fclose(f);
    return true;
}

I think the error here

    int main(int argc, char *argv[])
{
    // Check for correct number of args
    if (argc != 2 && argc != 3)
    {
        printf("Usage: ./speller [DICTIONARY] text\n");
        return 1;
    }

    // Structures for timing data
    struct rusage before, after;

    // Benchmarks
    double time_load = 0.0, time_check = 0.0, time_size = 0.0, time_unload = 0.0;

    // Determine dictionary to use
    char *dictionary = (argc == 3) ? argv[1] : DICTIONARY;

    // Load dictionary
    getrusage(RUSAGE_SELF, &before);
    bool loaded = load(dictionary);
    getrusage(RUSAGE_SELF, &after);

    // Exit if dictionary not loaded
    if (!loaded)
    {
        printf("Could not load %s.\n", dictionary);
        return 1;
    }

    // Calculate time to load dictionary
    time_load = calculate(&before, &after);

    // Try to open text
    char *text = (argc == 3) ? argv[2] : argv[1];
    FILE *file = fopen(text, "r");
    if (file == NULL)
    {
        printf("Could not open %s.\n", text);
        unload();
        return 1;
    }

1 Answer 1

1
Could not unload dictionaries/large.

means your unload returned false, telling the programme that it failed to unload. Implement unload according to the specification.

Could not open text.

means there is no file named text in the current directory. Not sure what you expected to happen instead.

2
  • from you, I understand the first problem and I solved but second I didn't understand Commented Mar 4, 2020 at 18:18
  • You are meant to provide the name of a text file, if not in current directory then with a path, like texts/lalaland.txt, where current directory contains directory texts, which contains text file lalaland.txt.
    – Blauelf
    Commented Mar 4, 2020 at 18:24

You must log in to answer this question.

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