/*
编写一个程序,读取输入,直至读到EOF,报告读入的单词数、大写字母数、小写字母数、标点
符号数和数字字符数。使用ctype.h头文件中的函数。
*/
//测试字符串?
//ajskm,dl kdAj,.lfj sjkdl ?sdk12lfj !.,fkdj.,.lssd.1a
//(ajskm),(dl) (kdAj),.(lfj) (sjkdl) ?(sdk)12(lfj) !.,(fkdj).,.(lssd).1(a)
#include<stdio.h>
#include <ctype.h>
#define SIZE 100
int count_word(char *string);
int main(void)
{?? ?
?? ?int i,count_up=0,count_low=0,count_pun=0,count_dig=0,word=0;
?? ?char string[SIZE];
?? ?fgets(string, SIZE, stdin);
?? ?for(i=0;string[i] != '\0';i++)
?? ?{
?? ??? ?if(isupper(string[i]))
?? ??? ??? ?count_up++;
?? ??? ?else if(islower(string[i]))
?? ??? ??? ?count_low++;
?? ??? ?else if(ispunct(string[i]))
?? ??? ??? ?count_pun++;
?? ??? ?else if(isdigit(string[i]))
?? ??? ??? ?count_dig++;
?? ??? ?else continue;
?? ?}
?? ?word=count_word(string);
?? ?printf("up=%d\nlow=%d\npun=%d\ndig=%d\nword=%d\n",count_up,count_low,count_pun,count_dig,word);
?? ?return 0;
}
int count_word(char *string)
{
?? ?int i,count=0;
?? ?int in_word=0;
?? ?
?? ?for(i=0;i<SIZE;i++)?
?? ?{
?? ??? ?if(isalpha(string[i]))
?? ??? ??? ?in_word=1;
?? ??? ?else if(in_word&&isalpha(string[i])==0)
?? ??? ?{
?? ??? ??? ?count++;
?? ??? ??? ?in_word=0;?? ??? ?
?? ??? ?}
?? ??? ?else if(in_word&&string[i]=='\0')
?? ??? ?{
?? ??? ??? ?count++;
?? ??? ??? ?in_word=0;
?? ??? ?}
?? ??? ?else in_word=0;
?? ?}
?? ?return count;
}