我有一个递归struct
,它是:
typedef struct dict dict;
struct dict {
dict *children[M];
list *words[M];
};
以这种方式初始化:
dict *d = malloc(sizeof(dict));
bzero(d, sizeof(dict));
我想知道bzero()
这里到底做了什么,我怎样才能malloc()
为孩子们递归。
编辑:这就是我希望能够malloc()
和:children
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);
}
}