Kodewick
Start learning →
Mini challenge←→0 / 70

Diary word count

#068Mini challengeStringsConditions6 min

The English diary needs enough words. Write count_words(s) to count the words in s. Words are separated by spaces, maybe several, and there may be spaces at the start or end; an empty string gives 0.

Examples
count_words("went to the zoo")→4
count_words("")→0
The functionint count_words(const char *s)
main.c
int count_words(const char *s) {
    int words = 0;
    for (int i = 0; s[i] != '\0'; i++) {
        // your code here: not a space, and first or after a space, means a new word
    }
    return words;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.