0

I'm working on my load function to obtain the "word" from dictionary and I obtain one of the next message

dictionary.c:59:28: error: use of undeclared identifier 'word'; did you mean 'load'? while(fscanf(Dict,"%c",word))

The node for word is defined as;

typedef struct node
{
    char word[LENGTH + 1];
    struct node *next;
}
node;

Could I consider when entering dictionary word as a "full" word (string, as a string is a *char)? Why isn't word identified?

my code is

    bool load(const char *dictionary)
{
    // Opens dictionary
    FILE *Dict = fopen(dictionary,"r");

    if(Dict==NULL)
    {
        printf("Could not open Dictionary\n");
        return false;
    }

    // Read strings from Dictionary

    while(fscanf(Dict,"%c",word))
    {
        node *new_word = malloc(sizeof(node));
        
        if(new_word == NULL)
        {
            fclose(Dict);
            return false;
        }
        
        else // Hash table
        {
            strcpy(new_word->word,word); //Copies word to new_word node
            new_word->next=table[hash(word)]; // Next pointer to NULL at first, then first linked list
            table[hash(word)]=new_word; // hash table pointer to 
        }
    }
    return false;
}

1 Answer 1

2

There are a couple problems there.

while(fscanf(Dict,"%c",word))

First, word hasn't been declared or created inside of load. I assume it doesn't exist as a global variable either. (It may be declared inside of check, but it would only exist inside of check, not in any other function.) The compiler is dumb. It's just trying to guess what you meant by suggesting load.

Next, even after you declare word, the statement should be using %s, a string placeholder, not %c, a char placeholder.

This should get you going again.

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

You must log in to answer this question.

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