Kodewick
学びはじめる →
ミニチャレンジ←→0 / 70

日記の単語数

#068ミニチャレンジ約 6 分

英語の日記は、ある程度の単語数が必要です。s の単語の数を数える count_words(s) を書きましょう。単語はスペースで区切られていて、スペースが続くこともあり、最初や最後にスペースがあることもあります。空の文字列なら 0 です。

例
count_words("went to the zoo")→4
count_words("")→0
関数int count_words(const char *s)
main.c
int count_words(const char *s) {
    int words = 0;
    for (int i = 0; s[i] != '\0'; i++) {
        // ここにコードを書く:スペースではなく、しかも先頭かスペースの直後なら、新しい単語
    }
    return words;
}
Ctrl + Enter でも実行できます
結果

実行すると例で試せます。よさそうなら提出しましょう。