How to write a C Program String Count in C Programming Language ?
Solution For C Program :
//C Program String Count.
#include <stdio.h>
#include <ctype.h>
int main(){
char s[1005];
gets(s);
int count[26] = {0};
int i;
for( i = 0 ; s[i] != '\0' ; i++ ){
s[i] = tolower(s[i]);
/*
if( s[i] == 'a' ){
count[0]++;
}
else if( s[i] == 'b' ){
count[1]++;
}
else if( s[i] == 'c' ){
count[2]++;
}
else if( s[i] == 'd' ){
count[3]++;
}
else if( s[i] == 'e' ){
count[4]++;
}
...
*/
if( islower(s[i]) ){
int index = s[i] - 'a';
count[index]++;
}
}
for( i = 0 ; i < 26 ; i++ ){
printf("%c: %d\n", i+'a', count[i]);
}
return 0;
}