/* This program reads characters from the keyboard
   and counts the number of a's, b's, etc. and non-letters
*/

#include <stdio.h>

int main () {
  int count [27] ;  /* count[0]..count[25] gives counts for a..z
                       count[26] counts non-letters */
  int ch;           /* the next character to be read
                       declared as int, so can compare with EOF (=-1) */
  int i;            /* index variable for loops */

  /* initialize count array */
  for (i = 0; i < 27; i++)
    count[i] = 0;

  /* read letters and record counts */
  while ((ch = getchar()) != EOF) {
    ch = tolower(ch);  /* convert letter, if present, to lower case */
    if (('a' <= ch) && (ch <= 'z'))
      count[ch-'a']++ ;
    else
      count[26]++;
  }
  
  /* print frequency counts */
  printf ("\nFrequency Count of Characters\n");
  for (i = 0; i < 26; i++) 
    printf ("%c: %3d\n", 'a'+i, count[i]);
  printf ("?: %3d\n", count[i]);
  
}
