#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
    char text[1000]; // 入力文章を格納する配列
    int word_count = 0; // 単語数のカウント
    int in_word = 0;    // 現在単語の中かどうかを示すフラグ

    // ユーザーから文章を入力
    printf("文章を入力してください: ");
    fgets(text, sizeof(text), stdin); // 改行含む入力を取得

    // 入力文章を解析して単語数をカウント
    for (int i = 0; text[i] != '\0'; i++) {
        if (isspace(text[i])) { // 空白文字の場合
            in_word = 0;        // 単語の外にいる
        } else if (!in_word) {  // 単語の中に入る
            in_word = 1;        // フラグを立てる
            word_count++;       // 単語数をインクリメント
        }
    }

    // 結果を出力
    printf("単語数: %d\n", word_count);

    return 0;
}
