/* File: freq.c

   Counts the frequencies of letters in the input.
*/

#include <stdio.h>
#include "simpio.h"
#include "genlib.h"
#include "strlib.h"

main() {
   string str ;
   int index, i, length, freq[26] ;
   char c ;

   /* Initialize array */
   for (i = 0 ; i < 26 ; i++) {
      freq[i] = 0 ;
   }

   /* Get Input */
   printf("Enter a line: ") ;
   str = GetLine() ;
   length = StringLength(str) ;

   /* Compute frequencies */
   for (i = 0 ; i < length ; i++) {
      c = IthChar(str, i) ;
      if ( isalpha(c) ) {
	c = tolower(c) ;
	index = c - 'a' ;
	freq[index]++ ;  
      } 
   }

   /* Report frequencies */
   for (i = 0 ; i < 26 ; i++) {
      c = 'a' + i ;
      printf("The letter %c appeared %d times\n", 
	      c, freq[i]) ;
   }
}
