#include<stdio.h> #include<string.h> int count[100];//注意该变量定义为全局变量,保存各种字符的个数; int* Count(char *s) { int i,char_count=0,num_count=0,k_count=0,other_count=0; for(i=0;*(s+i)!='\0';i++) { //printf("%c ",*(s+i)); if((*(s+i)>='a'&&*(s+i)<='z')||(*(s+i)>='A'&&*(s+i)<='Z')) count[0] = ++char_count; //注意前++与后++的区别 if(*(s+i)>='0'&&*(s+i)<='9') count[1] = ++num_count; if(*(s+i)==' ') count[2] = ++k_count; } other_count = i-char_count-num_count-k_count; count[3] = other_count; return count; } int main() { int i,*ptr; char s[100]; gets(s); ptr = Count(s); for(i=0;i<4;i++) { printf("%d ",*(ptr+i)); } return 0; }
0.0分
0 人评分