35 lines
637 B
C
35 lines
637 B
C
|
#include <stdlib.h>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
|
||
|
void print_histogram(char string[]);
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
char test[] = "I am a test and im diggin a test... diggy diggy test...";
|
||
|
printf("%s\n",test);
|
||
|
print_histogram(test);
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void print_histogram(char string[]){
|
||
|
char num_letters['z' - 'a'];
|
||
|
for(char i = 0; i <= 'z' - 'a'; i++){
|
||
|
num_letters[i] = 0;
|
||
|
}
|
||
|
char i = 0;
|
||
|
while(string[i] != '\0'){
|
||
|
if(string[i] >= 'a' && string[i] <= 'z'){
|
||
|
num_letters[string[i]-'a']++;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
|
||
|
for(char i = 0; i <= 'z' - 'a'; i++){
|
||
|
if(num_letters[i] != 0){
|
||
|
printf("%c -> %d\n", i + 'a', num_letters[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|