1 #include<stdio.h> 2 3 int main(void) 4 { 5 char ch; 6 int start; 7 int count; 8 9 ch = getchar(); 10 count = 0; 11 /*单词开始标志,1表示单词开始,0表示单词结束*/ 12 start = 0; 13 14 while (ch != ' ') 15 { 16 if (ch != ' ') 17 { 18 start = 1; 19 } 20 21 if (start == 1 && ch == ' ') 22 { 23 count++; 24 start = 0; 25 } 26 ch = getchar(); 27 } 28 /*假设最后一个单词,然后结束输入*/ 29 if (start == 1) 30 { 31 count++; 32 } 33 34 printf("%d", count); 35 36 return 0; 37 }