c语言怎么编写统计一个字符串中各个字符的个数

c语言怎么编写统计一个字符串中各个字符的个数

第1个回答  2015-12-29

void getNum(char *str) 

{int i,a[26]={0},A[26]={0};     

 for(;*str;str++)     

if(*str>='A'&&*str<='Z')A[*str-'A']++;

else if(*str>='a'&&*str<='z')a[*str-'a']++;

 for(i=0;i<26;i++)

if(A[i])printf("%c:%d\n",'A'+i,A[i]);

 for(i=0;i<26;i++)

if(a[i])printf("%c:%d\n",'a'+i,a[i]);

}

void main()

 {

 int num;

 char *testStr = "How are you? Fine Thank you!"; 

 getNum(testStr); 

 getch(); 

 }

本回答被网友采纳
相似回答