diff options
| author | mo khan <mo.khan@gmail.com> | 2020-06-14 21:57:08 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-06-14 21:57:08 -0600 |
| commit | c687bfe6008bc7a2870e676873c87cd733ebc444 (patch) | |
| tree | e1c9728273b38a1fb8891d3402534607ab380a9b /words.c | |
| parent | fd9bfc42af1ae0a070558524d7e384eede8d9083 (diff) | |
Add test using mocks
Diffstat (limited to 'words.c')
| -rw-r--r-- | words.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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); +} |
