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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:02:12+00:00 2026-06-12T20:02:12+00:00

I’ve been trying to make a tree with directories with pointers in C. I

  • 0

I’ve been trying to make a tree with directories with pointers in C.

I thought it would be easier to use some kind of struct with pointers, which would resemble a class in Java.

so I would using something like this:

  struct d
  {
      struct d *up /*point to parent*/
      struct d *down /*point to child*/
      struct d *right /*point to right*/
  }

  generate_tree(struct **d)
  {
   /*my code*/
  }

I’m trying to make multiple struct d’s and connect them. So what I’m assuming that I have to do is create and allocate a pointer for the directory then initialize a struct d and have the created pointer to point inside the struct d. My question is how would I create the d and set the *up, *down, and *right?

Thanks for helping

  • 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-12T20:02:14+00:00Added an answer on June 12, 2026 at 8:02 pm

    You dynamically allocate a struct d with malloc(). Ie,

    struct d *dp = malloc(sizeof(*dp));
    

    Once you have a pointer to an newly-created struct d, you assign to it’s fields just like any other C structure:

    dp->up = /* ... */;
    dp->down = /* ... */;
    dp->right = /* ... */;
    

    The trick, of course, is what you assign to those fields. Well, from their types, struct d *, it has to be a pointer to a struct d. So, either you assign the NULL pointer constant, which indicates there’s nothing there, or you assign the address of some other structd d objects. For example,

    struct d *up = malloc(sizeof(*up));
    struct d *down = malloc(sizeof(*down));
    struct d *right = malloc(sizeof(*right));
    
    d->up = up;
    d->down = down;
    d->right;
    

    I don’tknow if this struct is intended to be more than a toy example, but it looks like a node in some sort of tree structure. If that’s the case, you’d want to write various helper functions that hide most of this pointer manipulation.

    struct d *new_node() { /* allocate a new d,  set all fields to NULL */ }
    void insert_node_in_tree(struct d *tree, struct d *node) { ... }
    

    and so on for the relevant operations on whatever it is you’re building.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to select an H1 element which is the second-child in its group
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has

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.