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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:44:19+00:00 2026-05-27T02:44:19+00:00

I have a recursive struct which is: typedef struct dict dict; struct dict {

  • 0

I have a recursive struct which is:

typedef struct dict dict;
struct dict {
    dict *children[M];
    list *words[M];
};

Initialized this way:

dict *d = malloc(sizeof(dict));
bzero(d, sizeof(dict));

I would like to know what bzero() exactly does here, and how can I malloc() recursively for children.

Edit: This is how I would like to be able to malloc() the children and words:

void dict_insert(dict *d, char *signature, unsigned int current_letter, char *w) {
    int occur;
    occur = (int) signature[current_letter];
    if (current_letter == LAST_LETTER) {
        printf("word found : %s!\n",w);
        list_print(d->words[occur]);
        char *new;
        new = malloc(strlen(w) + 1);
        strcpy(new, w);
        list_append(d->words[occur],new);
        list_print(d->words[occur]);
    }
    else {
        d = d->children[occur];
        dict_insert(d,signature,current_letter+1,w);
    }
}
  • 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-27T02:44:20+00:00Added an answer on May 27, 2026 at 2:44 am

    In general, when you are unsure what the compiler is generating for you, it is a good idea to use a printf to report the size of the struct. In this case, the size of dict should be 2 * M * the size of a pointer. In this case, bzero will fill a dict with zeros. In other words, all M elements of the children and words arrays will be zero.

    To initialize the structure, I recommend creating a function that takes a pointer to a dict and mallocs each child and then calls itself to initialize it:

    void init_dict(dict* d)
    {
        int i;
        for (i = 0; i < M; i++)
        {
            d->children[i] = malloc(sizeof(dict));
            init_dict(d->children[i]);
    
            /* initialize the words elements, too */
        }
    }
    

    +1 to you if you can see why this code won’t work as is. (Hint: it has an infinite recursion bug and needs a rule that tells it how deep the children tree needs to be so it can stop recursing.)

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

Sidebar

Related Questions

I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I have a recursive algorithm which steps through a string, character by character, and
I have a recursive table in which each record has an ID and a
i have this recursive code <ul> <% sql=SELECT * FROM cats ORDER BY orderid
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
I have a recursive object, a linked list really: public class LinkedList { public
Hi I have a boost graph like: struct Vertex; struct Edge; typedef boost::adjacency_list<boost::vecS, boost::vecS,
Is it possible to have mutual recursive types ( [<Struct>] ) spread across different
i have a Trie and several functions modifiing it. typedef struct node *pnode; typedef
I have a recursive method on the base form that takes in a control

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.