/* 编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。 */ #include<stdio.h> void count(char s[]); int main(void) { char s[100]; gets(s); count(s); return 0; } void count(char s[]) { int a[4]={0}; while(*s) { if((*s >='a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z')) a[0]++; else if( *s >= '0' && *s <= '9') a[1]++; else if(*s == ' ') a[2]++; else a[3]++; s++; } printf("%d %d %d %d",a[0],a[1],a[2],a[3]); }
0.0分
6 人评分