Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int * count_chars(const char *a, int *counts){
  int len1 = strlen(a);
 
  printf("\n\nCounts for %s\n", a);
  for(int i=0;i<len1;i++){
    char ch = tolower(a[i]);

    if(ch >= 'a' && ch <= 'z'){
      counts[ch - 'a']++;
    }
  }

  return counts;
}

void display_char_counts(const char *phrase){

  int counts[26] = {0};
  int *count = count_chars(phrase, counts);

  for(int i=0;i<26;i++){
    if(counts[i] > 0){
      printf("\n %c: %d", 'a' + i, counts[i]);
    }
  }
}

int main(int argc, char *argv[]) {
  
  display_char_counts("abbcccdddd");
  display_char_counts("See Jane run");
  


  return 0;
}