ref: 783f6d8fcd85aaa04d843d3ac282b7dc238b4c2c
parent: 30d7ba73ff01b66e88e28faa260583935a20c1d7
parent: 4570b488dd26cd93553057ce01354dbcdcdbb192
author: eli <eli@cloud9>
date: Mon May 13 16:16:13 EDT 2024
merge
--- a/anagrams.c
+++ b/anagrams.c
@@ -96,7 +96,7 @@
}
void
-common(void)
+common(char *input)
{
dlist *cur = dict;
int i;
@@ -103,9 +103,11 @@
char *commonwords[] = {"a", "I", "an", "at", "be", "by", "do", "he", "in", "is", "it", "my", "no", "oh", "or", "to", "us", "we", "and", "but", "for", "her", "him", "his", "its", "not", "too", "you", nil};
for(i = 0; commonwords[i] != nil; i++){
- cur->word = strdup(commonwords[i]);
- cur->next = calloc(1, sizeof(dlist));
- cur = cur->next;
+ if (contains(input, commonwords[i])) {
+ cur->word = strdup(commonwords[i]);
+ cur->next = calloc(1, sizeof(dlist));
+ cur = cur->next;
+ }
}
}
@@ -121,6 +123,7 @@
dlist *cur;
item *child;
int i;
+ int commonwords = 0;
dict = calloc(1, sizeof(dlist));
@@ -131,7 +134,7 @@
minlen = atoi(argv[i]);
continue;
}else if (argv[i][1] == 'c'){
- common();
+ commonwords = 1;
continue;
}
}else continue;
@@ -150,6 +153,9 @@
removechars(input, " ");
while(contains(input, "'"))
removechars(input, "'");
+
+ if (commonwords == 1)
+ common(input);
cur = dict;
while(cur->word != nil)