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

  • SEARCH
  • Home
  • 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 8294421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:12:41+00:00 2026-06-08T14:12:41+00:00

#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include dictionary.h #define HASH_SIZE 100 //

  • 0
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "dictionary.h"

#define HASH_SIZE 100

// prototype
int hash(char *word);

// counter
int counter;

// node
typedef struct
{
    char *word;
    node *next;
} node;

// hash table
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))
    {
        // get word into a string
        char gotcha[LENGTH];
        fscanf(dict, "%s", gotcha);

        // declare a node and allocate memory
        node n;
        n.word = malloc( strlen(gotcha)*sizeof(char) );

        // save the word into the node
        strcpy(n.word, gotcha);

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

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

        //test
        int len = strlen(n.word);
        printf("%s\n", n.word);
        printf("%i\n", len);

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


    fclose(dict);

    return true;
}

I am receiving the following two errors on these two lines of code:

    n.next = hashtable[hash_value];
    hashtable[hash_value] = &n;

dictionary.c:89:16: error: assignment from incompatible pointer type [-Werror]
dictionary.c:90:31: error: assignment from incompatible pointer type [-Werror]
How do I save pointer values in these two places? I am new to this, so please bear that in mind. 🙂

  • 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-08T14:12:42+00:00Added an answer on June 8, 2026 at 2:12 pm

    In your structure, the type node is not yet defined. Change it to use the structure tag:

    typedef struct node
    {
        char *word;
        struct node *next;
    } node;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include dictionary.h #define HASH_SIZE
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<stdbool.h> char** parser(char *message) { char a[9][256]; char* tmp =message; bool
# include <stdio.h> # include <stdbool.h> # include <string.h> # include <stdlib.h> int main
Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> typedef struct node { char*
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
This is the code #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
#include<stdio.h> #include<string.h> #define USER_MEM (10*1024) typedef struct { unsigned short int vol_level; int mute_stat;
#include <stdio.h> #include <stdlib.h> #define calc(a,b) (a*b)/(a-b) void calculate(){ int a = 20, b
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> /*Define custom functions */ void insertElement(); bool elementExists();
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =

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.