summaryrefslogtreecommitdiff
path: root/words.c
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-06-14 21:57:08 -0600
committermo khan <mo.khan@gmail.com>2020-06-14 21:57:08 -0600
commitc687bfe6008bc7a2870e676873c87cd733ebc444 (patch)
treee1c9728273b38a1fb8891d3402534607ab380a9b /words.c
parentfd9bfc42af1ae0a070558524d7e384eede8d9083 (diff)
Add test using mocks
Diffstat (limited to 'words.c')
-rw-r--r--words.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/words.c b/words.c
index b9c236a..f5bac5f 100644
--- a/words.c
+++ b/words.c
@@ -1,3 +1,4 @@
+#include <stdlib.h>
#include <string.h>
int split_words(char *sentence) {
@@ -11,3 +12,14 @@ int split_words(char *sentence) {
}
return count;
}
+
+void words(const char *sentence, void (*callback)(const char *, void *), void *memo) {
+ char *words = strdup(sentence);
+ int word_count = split_words(words);
+ char *word = words;
+ while (word_count-- > 0) {
+ (*callback)(word, memo);
+ word = word + strlen(word) + 1;
+ }
+ free(words);
+}