C语言中怎样统计一篇文章中英文单词个数

2025-04-17 04:12:49
推荐回答(1个)
回答1:

#include
#include
int main()
{
char text[1024] = "";
int i;
int count = 0;
printf("Please input text:");
gets(text);
for(i = 0;i < strlen(text);i++)
{
if(text[i] <= 'z' && text[i] >= 'a' || text[i] <= 'Z' && text[i] >= 'A')
{
count++;
}
}
printf("The English words number is %d\n",count);
getch();
return 0;
}