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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:04:12+00:00 2026-06-01T13:04:12+00:00

I am working through Learn C The Hard Way and am stumped on something.

  • 0

I am working through Learn C The Hard Way and am stumped on something. I’ve written a simplified version of the problem I am running into to make it easier to get down to it:

#include <stdlib.h>

#define GROUP_SIZE 10
#define DATA_SIZE 64

struct Dummy {
    char *name;
};

struct Group {
    struct Dummy **dummies;
};

int main() {
    struct Group *group1 = malloc(sizeof(struct Group));
    group1->dummies = malloc(sizeof(struct Dummy) * GROUP_SIZE);
    struct Dummy *dummy1 = group1->dummies[3];

    // Why does this seg fault?
    dummy1->name = (char *) malloc(DATA_SIZE);

    return 0;
}

When I try to set the name pointer on one of my dummies I get a seg fault. Using valgrind it tells me this is uninitialized space. Why is this?

  • 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-01T13:04:13+00:00Added an answer on June 1, 2026 at 1:04 pm

    Your use of dummies appears inconsistent with its declaration. From the way you use the dummies field it appears that dummies was intended as an array of Dummy structs, not an array of arrays of Dummy structs. If this is the case, change your declaration to this:

    struct Group {
        struct Dummy *dummies; // Single asterisk
    };
    

    Then change your usage as follows:

    struct Dummy *dummy1 = &group1->dummies[3];
    

    Of course this assumes that GROUP_SIZE is four or more.

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

Sidebar

Related Questions

Working my way through Learn Python the Hard Way ex.25, and I just can't
I'm working through learn python the hard way , and in exercise 33 extra
I am working my way through Learn Cocoa on the Mac which was written
I am trying to learn R by working through this ProjectEuler problem using R.
I've been recently working my way through Programming Language Pragmatics 3rd ed to learn
I am working through trying to learn to program in Python and am focused
Ok, I am working through a book and trying to learn C++ operator overloading.
I've been trying to learn some programming on my own by working through the
Trying to learn C++ and working through a simple exercise on arrays. Basically, I've
I'm working through the Ruby on Rails 3 Tutorial: Learn Rails by Example by

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.