输入一串字符,统计单词的个数
#include<stdio.h>int sort(char ch);
int main(void)
{
char ch;
int i,j,count=1,letter;
printf("Enter characters:");
ch=getchar();
i=j=sort(ch);
while(ch!='\n'){
if(j!=sort(ch)){
j=sort(ch);
count++;
}
ch=getchar();
}
if(i==0&&j==0)
letter=(count-1)/2;
else if((i==0&&j!=0)||(i!=0&&j==0))
letter=count/2;
else (count+1)/2;
printf("单词个数为%d",letter);
printf("\n");
return 0;
}
int sort(char ch)
{
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
return 1;
else return 0;
}