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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:11:26+00:00 2026-06-10T15:11:26+00:00

Im toying with creating my own hash table data structure, but I have hit

  • 0

Im toying with creating my own hash table data structure, but I have hit an unexpected problem, which I can’t solve and haven’t found a satisfying solution for it yet.

See, I have this linked list struct

struct Link
{
   int v;
   struct Link* next;
}

and then inside the hash table structure I want keep track of an array linked lists, like this:

struct Link** entries;

What I run into is, that for this to work, I first have to initialize the array like this:

entries = malloc(sizeof(struct Link*) * N);

for (i = 0; i < N; i++)
   entries[i] = malloc(sizeof(struct Link));

What I want is not having to do the for loop that initializes the structs, because that’s not how linked lists work, I want to leave entries[x] blank until it actually gets assigned a value.

If I don’t do the for loop this happens:

if (entries[x] != NULL)  /* true, the array is initialized */
  entries[x]->v = value; /* SEGFAULT, there is no struct initialized */

That if statement ‘should’ return false if I haven’t assigned a Link struct to it yet, but it doesn’t.

One way of solving this problem is to just initialize all the first links of the linked list with that for loop and then checking for the value, but that’s not what I want.

So does anyone know a way to solve this the way I want it to?

  • 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-10T15:11:28+00:00Added an answer on June 10, 2026 at 3:11 pm

    You can use calloc rather than malloc while allocating entries like:

    entries = calloc(sizeof(struct Link*),  N);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem creating my own librairie to send email. This is my
When creating my own macro, and trying to add it so that anyone can
I'm currently creating my own CMS and I have a hard question (I think
I'm in the process of creating my own framework and have been looking at
I am creating my own email tracking system for email marketing tracking. I have
I'm trying to build my own Hash Table in C from scratch as an
I am creating my own file tagging system for an application and have not
Im currently creating my own forum for my website and i have read plenty
I'm quite familiar with Java as I'm actually creating my own app. But I
I have been working through the tutorial at http://bkiers.blogspot.de/2011/03/creating-your-own-programming-language.html . In short, a small

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.