Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:39:27+00:00 2026-06-08T17:39:27+00:00

#define HASH_SIZE 5 // prototype int hash(char *word); // counter int counter; // node

  • 0
#define HASH_SIZE 5

// prototype
int hash(char *word);

// counter
int counter;

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

// hash table
struct node *hashtable[HASH_SIZE];
  bool
load(const char *dictionary)
{
    // open the dictionary
    FILE *dict = fopen(dictionary, "r");
    if(dict == NULL)
    {
        printf("Could not open %s.\n", dictionary);
        return false;
    }

    // set all values in the hash table to null
    for(int i = 0; i < HASH_SIZE; i++)
    {
        hashtable[i] = NULL;
    }

    // set the counter to 0
    counter = 0;

    // iterate through the words in the dictionary
    while (!feof(dict))
    {
        //declare a node
        node *n = malloc( sizeof(node) );

        // copy the word into the node
        fscanf(dict, "%s", n.word);

        // hash the word
        int hash_value = hash(n.word);

        // start saving addresses to the hashtable
        n.next = hashtable[hash_value];
        hashtable[hash_value] = &n;

        // that's one more!
        counter++;
    }


    fclose(dict);

    return true;
}

For the following lines:

        //declare a node
    node *n = malloc( sizeof(node) );
// hash the word
    int hash_value = hash(n.word);

    // start saving addresses to the hashtable
    n.next = hashtable[hash_value];
    hashtable[hash_value] = &n;r code here

I receive the following error messages:

dictionary.c: In function ‘load’:
dictionary.c:112:29: error: request for member ‘word’ in something not a structure or union
dictionary.c:135:32: error: request for member ‘word’ in something not a structure or union
dictionary.c:138:10: error: request for member ‘next’ in something not a structure or union
dictionary.c:139:31: error: assignment from incompatible pointer type [-Werror]

What’s the issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:39:29+00:00Added an answer on June 8, 2026 at 5:39 pm

    Really simple:

    node *n = malloc( sizeof(node) );
    fscanf(dict, "%s", n.word);
    

    n is a pointer to a node, but n.word implies that n itself is a node. For a pointer, the syntax is a little different.

    fscanf(dict, "%s", n->word);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a hash table defined like this typedef std::unordered_map<unsigned long long int,unsigned long long
#define MAX 100 struct bs{ int ab; int ac; }be; struct s{ be b;
I have a structure of type: struct hashnode_s { struct hashnode_s *next; char *key;
I would like to define a hash table with a swappable hash function. The
To implement an open hash table in C++, I thought I'd define a vector
#define BUF_SIZE 10 char *html = foo:baa\r\nxxx:yyyy:\r\nLocation:........................................\r\Connection:close\r\n\r\n; char *p = (char*)html, *buf, *pbuf, *tbuf;
#define HISTORY_SIZE 50 #define INPUT_SIZE 512 /*Max input size*/ char input[INPUT_SIZE]; /*Holding user input
Let's say I want to build a perfect hash table for looking up an
I want to define std::tr1::hash<boost::tuple<A,B,C> > . But I get an error that doesn't
I'm creating a hash table in Perl, of an unknown size. The hash table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.