I have a string. Now I want to count the frequency of each letter a->b, A->B appear in the string. I try to do that like this:
My question is: Is there a shorter way doing that?Code:for(i=0;i<strlen(str);i++){ if ( str[i] == 'a') a++; else if ( str[i] == 'b') b++; else if ( str[i] == 'c') c++; else if ( str[i] == 'd') d++; else if ( str[i] == 'e') e++; else if ( str[i] == 'f') f++; else if ( str[i] == 'g') g++; else if ( str[i] == 'h') h++; else if ( str[i] == 'i') i++; else if ( str[i] == 'j') j++; else if ( str[i] == 'k') k++; else if ( str[i] == 'l') l++; else if ( str[i] == 'm') m++; else if ( str[i] == 'n') n++; else if ( str[i] == 'o') o++; else if ( str[i] == 'p') p++; else if ( str[i] == 'q') q++; else if ( str[i] == 'r') r++; else if ( str[i] == 's') s++; else if ( str[i] == 't') t++; else if ( str[i] == 'u') u++; else if ( str[i] == 'v') v++; else if ( str[i] == 'w') w++; else if ( str[i] == 'x') x++; else if ( str[i] == 'y') y++; }