#include<stdio.h>
#include<ctype.h>
int Reroop();
void function();
int main(int argc,char **argv){
for(fputs("Enter to quit:->",stdout);Reroop();function(),fputs("Enter to quit:->",stdout));
return 0;}
//
int Reroop(){
int ch=0,ch1=0;
ch=getchar();
if(ch&&ch!=EOF&&ch!=10) while((ch1=getchar())!=EOF&&ch1!=10);
if(!ch||ch==EOF||ch==10) return 0;
else return 1;
}
void function(){
int ch=0;
char *statis_title[8]={"控制字符:","空白字符:","数字:","小写字母:","大写字母:","标点符号:","不可打印字符:","总字符数:"};
int statis_value[8]={};
int (*pfunc[8])(int)={iscntrl,isspace,isdigit,islower,isupper,ispunct,isprint,NULL};
for(fputs("Input something:->",stdout);(ch=getchar())&&ch!=EOF&&ch!=10;){
int i=0,value=0;
for(;*(pfunc+i)&&!(value=(*(pfunc+i))(ch)?(i!=6?1:0):(i==6?1:0))/*!(value=((*(pfunc+i))(ch)&&i!=6||!(*(pfunc+i))(ch)&&i==6))*/;i++);
if(value) *(statis_value+i)+=value;
(*(statis_value+7))++;
}
fputs("个数->百分比:\n",stdout);
for(int i=0;i<7;i++){
fputs(*(statis_title+i),stdout);
printf("%d->%0.2f%%\n",*(statis_value+i),(statis_value+i)*100.0/(*(statis_value+7)));
}
fputs(*(statis_title+7),stdout);
printf("%d\n",*(statis_value+7));
}
|