ref: b57f2016149d82de9796a82826ed88f85e16a147
parent: a6ed04f41557953cd022f331ff5dfdb28e05ad2e
author: eli <eli@cloud9>
date: Fri May 10 00:26:43 EDT 2024
anagrams update
--- a/anagrams.c
+++ b/anagrams.c
@@ -78,8 +78,8 @@
if (strlen(child->input) == 0)
printf("%s\n", child->anagram);
-
- findanagrams(child, minlen);
+ else
+ findanagrams(child, minlen);
}
cur = cur->next;
@@ -145,24 +145,24 @@
items->children = calloc(1, sizeof(item*));
while(dict->word != nil){
- child = calloc(1, sizeof(item));
- child->input = strdup(items->input);
- child->anagram = strdup(items->anagram);
- child->children = calloc(1, sizeof(item*));
+ child = calloc(1, sizeof(item));
+ child->input = strdup(items->input);
+ child->anagram = strdup(items->anagram);
+ child->children = calloc(1, sizeof(item*));
- items->children = realloc(items->children, (items->nchildren+1) * sizeof(item*));
- items->children[items->nchildren] = child;
- items->nchildren++;
+ items->children = realloc(items->children, (items->nchildren+1) * sizeof(item*));
+ items->children[items->nchildren] = child;
+ items->nchildren++;
- removechars(child->input, dict->word);
- child->anagram = realloc(child->anagram, strlen(child->anagram) + strlen(dict->word) + 2);
- sprintf(&child->anagram[strlen(child->anagram)], "%s ", dict->word);
+ removechars(child->input, dict->word);
+ child->anagram = realloc(child->anagram, strlen(child->anagram) + strlen(dict->word) + 2);
+ sprintf(&child->anagram[strlen(child->anagram)], "%s ", dict->word);
- if (strlen(child->input) == 0)
- printf("%s\n", child->anagram);
- else
- findanagrams(child, minlen);
+ if (strlen(child->input) == 0)
+ printf("%s\n", child->anagram);
+ else
+ findanagrams(child, minlen);
- dict = dict->next;
+ dict = dict->next;
}
}