Debian Codegraph @

doc/tutorial_src/words.c

raw symbols SCIP
1 #include <string.h>
2
3 int split_words(char *sentence) {
4 int i, count = 1, length = strlen(sentence);
5 for (i = 0; i < length; i++) {
6 if (sentence[i] == ' ') {
7 sentence[i] = '\0';
8 count++;
9 }
10 }
11 return count;
12 }
13
14 void words(const char *sentence, void (*walker)(const char *, void *), void *memo) {
15 char *words = strdup(sentence);
16 int word_count = split_words(words);
17 char *word = words;
18 while (word_count-- > 0) {
19 (*walker)(word, memo);
20 word = word + strlen(word) + 1;
21 }
22 free(words);
23 }