- /**输入一行字符,统计其中的单词的个数.各单词之间用空格分隔,空格数可以是多个**/
- #include<stdio.h>
- #include<stdlib.h>
- int main(void)
- {
- int count=0;
- char temp;
- bool letter;
- letter=0;
- printf("输入一行字符单词,以空格分隔:/n");
- temp=getchar();
- while(temp!='/n'){
- if((letter==1)&&(temp==' ')){
- letter=0;
- }
- else if((temp>='a'&&temp<='z')||(temp>='A'&&temp<='Z')){
- if(letter==0){
- letter=1;
- count++;
- }
- }
- temp=getchar();
- }
- printf("the word'count is : %d/n",count);
- system("pause");
- return 0;
- }