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 7597857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:15:41+00:00 2026-05-30T22:15:41+00:00

The following code gives me the following errors : error: request for member ‘name’

  • 0

The following code gives me the following errors :

error: request for member ‘name’ in something not a structure or union
error: request for member ‘name’ in something not a structure or union
error: request for member ‘data’ in something not a structure or union
error: request for member ‘next’ in something not a structure or union

How could I fix it ?
Code is :

#define SIZE 5

typedef struct hashTable{
    int data;
    char *name;
    struct hashTable *next;
} table;


int hash_function(int value)
{
    return value % SIZE;
}

int insert(char *inFileName, table ***hashLinked)
{
    FILE *inFile;
    int val = -1;
    char str[30];
    int probe;

    if ((inFile = fopen(inFileName, "r")) == NULL)
    {
        fprintf(stderr,"Error opening input file, %s\n", inFileName);
        return -1;
    }
    while(fscanf(inFile,"%s %d",str,&val) == 2)
    {
        probe = hash_function(val);

        if(hashLinked[probe] == NULL)
        {                             
            **hashLinked[probe] = malloc(sizeof(table));   
            **hashLinked[probe]->name = (char *)malloc((strlen(str) + 1) * sizeof(char*));
            strcpy(**hashLinked[probe]->name,str);

            **hashLinked[probe]->data = val;
            **hashLinked[probe]->next = NULL;
        }                                             
        else
        {   
            table* hashLinkedNode = *hashLinked[probe];
            while(hashLinkedNode->next!=NULL)
            {                           
                hashLinkedNode = hashLinkedNode->next;
            }
            hashLinkedNode->next = malloc(sizeof(table));   
            hashLinkedNode->next->name = (char *)malloc((strlen(str) + 1) * sizeof(char*));
            strcpy(hashLinkedNode->next->name,str);  
            hashLinkedNode->next->data = val;
            hashLinkedNode->next->next = NULL;
        }
    } 
    fclose(inFile);
    return 0;
}


void printList(BookNode *hd)
{   
    for ( ; hd != NULL; hd = hd->next)
    {
        printf("[%s,%d]", hd->name, hd->isbn);
        if (hd->next)
            printf(" -> ");
    }
    printf("\n");
}

void printHashTable(BookNode **temp)
{
    BookNode *tmp = NULL;
    int i;
    for(i=0;i<SIZE;i++)
    {
        tmp = temp[i];
        while(tmp)
        {
            printf("%s %d",tmp->name, tmp->isbn);
            tmp=tmp->next;
        }
    }   
}

int main(int argc, char *argv[])
{
    table **hashLinked[SIZE];
    insert(argv[1],&hashLinked);
    printHashTable(**hashLinked);

    return 0;
}
  • 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-05-30T22:15:42+00:00Added an answer on May 30, 2026 at 10:15 pm

    One problem is that you call insert with something other than the type you declared it with,

    table **hashLinked[SIZE];
    insert(argv[1],&hashLinked);
    

    hashLinked is an array of pointers to pointers to table, so &hashLinked is a pointer to an array of pointers to pointers to table, but insert is declared to take a pointer to pointer to pointer to table. I’m less than confident that I really figured out what you intended to do, but what seems to be reasonable is that you want fewer levels of indirection. I believe the reason for passing &hashLinked is that you want hashLinked to be modified in insert, but that is already done by passing hashLinked itself, you needn’t pass its address. That would make the passed type compatible with the declared type, since as a function argument, hashLinked becomes a pointer to its first element, a table ***.

    Then you use inconsistent indirection counts in insert, and get the precedence of * and -> wrong, which causes the “request for member in something that isn’t a struct or union” errors. **hashLinked[probe]->name is parsed **(hashLinked[probe]->name), so tries to access the name member of a table * and then dereference that twice. With the parameter type table ***, the correct access would be (*hashLinked[probe])->name, get a table ** per hashLinked[probe], dereference that once to get a table * and access its (pointee)member name. However, you check if (hashLinked[probe] == NULL), and if so

    **hashLinked[probe] = malloc(sizeof(table));
    

    which is a guaranteed null pointer dereferencing. By the check and the following code, I believe that you actually want to have a parameter type of table **, the hashLinked parameter being an array of linked lists of tables, which makes the code far easier to follow. Filling in a BookNode type and adapting a few variables and parameters, I arrive at

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    #define SIZE 5
    
    typedef struct hashTable {
        int data;
        char *name;
        struct hashTable *next;
    } table;
    
    typedef struct book {
        int isbn;
        char *name;
        struct book *next;
    } BookNode;
    
    int hash_function(int value)
    {
        return value % SIZE;
    }
    
    int insert(char *inFileName, table **hashLinked)
    {
        FILE *inFile;
        int val = -1;
        char str[30];
        int probe;
    
        if ((inFile = fopen(inFileName, "r")) == NULL)
        {
            fprintf(stderr,"Error opening input file, %s\n", inFileName);
            return -1;
        }
        while(fscanf(inFile,"%s %d",str,&val) == 2)
        {
            probe = hash_function(val);
    
            if(hashLinked[probe] == NULL)
            {
                hashLinked[probe] = malloc(sizeof(table));
                hashLinked[probe]->name = (char *)malloc((strlen(str) + 1) * sizeof(char*));
                strcpy(hashLinked[probe]->name,str);
    
                hashLinked[probe]->data = val;
                hashLinked[probe]->next = NULL;
            }
            else
            {
                table* hashLinkedNode = hashLinked[probe];
                while(hashLinkedNode->next!=NULL)
                {
                    hashLinkedNode = hashLinkedNode->next;
                }
                hashLinkedNode->next = malloc(sizeof(table));
                hashLinkedNode->next->name = (char *)malloc((strlen(str) + 1) * sizeof(char*));
                strcpy(hashLinkedNode->next->name,str);
                hashLinkedNode->next->data = val;
                hashLinkedNode->next->next = NULL;
            }
        }
        fclose(inFile);
        return 0;
    }
    
    void printList(BookNode *hd)
    {
        for ( ; hd != NULL; hd = hd->next)
        {
            printf("[%s,%d]", hd->name, hd->isbn);
            if (hd->next)
                printf(" -> ");
        }
        printf("\n");
    }
    
    void printHashTable(table **temp)
    {
        table *tmp = NULL;
        int i;
        for(i = 0; i < SIZE; i++)
        {
            tmp = temp[i];
            while(tmp)
            {
                printf("%s %d",tmp->name, tmp->data);
                tmp = tmp->next;
            }
        }
    }
    
    int main(int argc, char *argv[])
    {
        if (argc < 2)
            return -1;
        table *hashLinked[SIZE];
        insert(argv[1],hashLinked);
        printHashTable(hashLinked);
        return 0;
    }
    

    which compiles warning-free and looks like it might do what you intended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code in javascript gives me the error this.callback is not a function
In the following code, g++ gives this error : 1.cpp: In member function void
I have the following code, which will not work. The javascript gives no errors
In C++ the following code gives a compiler error: void destruct1 (int * item)
In the sample code, the line with the 'error comment' gives the following the
Why does the following code NOT give an error, nor any type of a
I have the following code which retrieves data with a JSON request: // Replace
Why does the following code give me an error (g++ 4.1.2)? template<class A> class
The following code gives a segmentation fault on the last line require 'rubygems' gem
The following code gives a NullReferenceException since XPathSelectElement can't navigate through the XPath expression

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.