1、
#include <stdio.h> #include <ctype.h> #include <stdbool.h> int main(void) { char ch; bool word = false; bool space = false; int words = 0; while((ch = getchar()) != EOF) { if(!isspace(ch)) word = true; if(isspace(ch)) space = true; if(word && space) { words++; word = false; space = false; } } printf("words: %d.\n", words); return 0; }