.
This commit is contained in:
34
bac2/os/chap0/ex8.c
Normal file
34
bac2/os/chap0/ex8.c
Normal file
@ -0,0 +1,34 @@
|
||||
#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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user