//上机练习2
//******************************************************
//统计文本中单词的个数!
//******************************************************
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void main()
{
char text[1000];
int count=0;
int flag=0;
printf("请输入一行文本:\n");
gets(text);
for(int i=0;i<strlen(text);i++)
{
if(isalpha(text[i]) && flag==0)
{
count++;
flag = 1;
}
if(!isalpha(text[i]))
{
flag = 0;
}
}
printf("该文本串中有%d个单词\n",count);
}
请输入一行文本:
a test for my old pro
该文本串中有6个单词
请按任意键继续. . .