如输入:“How are you”,有3个单词和2个空格。
char str[80] = { 0 }; scanf("%[^\n]", str); int wordNum = 0; int spaceNum = 0; for (auto x : str) { if (isalpha(x)) wordNum++; if (x == ' ') spaceNum++; }