#include<stdio.h>
#include<string.h>
void countstr(char* st, int cutor[]);
void main()
{
char s[1000];
int counters[27] = {0}, i;
printf("Input a string\n");
gets(s);
countstr(s, counters);
for (i = 0; i <= sizeof(counters)/sizeof(counters[0])-2; i++)
printf("%c : %d\n", i + 65, counters[i]);
printf("others : %d\n", counters[i]);
}
void countstr(char* st, int cutor[])
{
int i, j;
char t;
i = strlen(st);
for (j = 0; j < i; j++)
{
t = st[j];
if (t >= 'a' && t <= 'z')
t = t - 'a' + 'A';
if (t >= 'A' && t <= 'Z')
cutor[t - 'A']++;
else
cutor[26]++;
}
}
输出结果: