搞了我好久分钟,饭都没吃
#include <stdio.h>
#include <conio.h>
#include <string.h>
struct alp{
char c;
int count;
}al[26];
int main(void){
int i,j;
int user[50]={0};
for(i='a';i<='z';i++){
al[i-97].c=i;
al[i-97].count=0;
}
printf("Please enter a string(len max is 50)\n");
i=0;
do{
user[i]=getchar();
i++;
}while(user[i-1]!='\n');
if(strlen(user)>50){
printf("Len is bigger then 50.");
getch();
return 1;
}
for(i=0;i<50;i++)
for(j=0;j<26;j++)
if(user[i]==al[j].c || user[i]==al[j].c-32){
al[j].count+=1;
break;
}
for(i=0;i<26;i++)
if(al[i].count)
printf("%c:%d\n",al[i].c,al[i].count);
getch();
}