题目链接: 习题6-1 分类统计字符个数 (15分)
#include <stdio.h> #define MAXS 15 void StringCount( char s[] ); void ReadString( char s[] ); /* 由裁判实现,略去不表 */ int main() { char s[MAXS]; //ReadString(s); gets(s); StringCount(s); return 0; } /* Your function will be put here */ void StringCount( char s[] ){ int i=0,j,a,b,c,d; a=b=c=d=0; while(s[i]!='\0'){ i++; } for(j=0;j<i;j++){ if(s[j]>='a'&&s[j]<='z'||s[j]>='A'&&s[j]<='Z'){ a++; }else if(s[j]==' '||s[j]=='\n'){ b++; }else if(s[j]>='0'&&s[j]<='9'){ c++; }else{ d++; } } printf("letter = %d, blank = %d, digit = %d, other = %d",a,b,c,d); }