Debian Codegraph @

doc/tutorial_src/words7.c

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