cours_progra/bac2/os/chap0/ex8.c
Debucquoy 4fd7542f03
.
2023-09-20 15:18:20 +02:00

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]);
}
}
}