#include<string.h> int main(){ char str[20]; int i, num = 0, word = 0; gets(str); for(i = 0; str[i] != '\0'; i++){ //if(!((str[i]>='A'&&str[i]<='Z') || (str[i]>='a'&&str[i]<='z')))//不是单词的话 if(str[i] == ' ') word = 0; else if(word == 0){ //是单词,而且Word == 0 word = 1; num++; } } printf("the number is:%d", num); return 0; }