/*
line_hist.c

Displays a histogram showing the line-length frequency of the 
input.  The histogram shows counts for lines of length 0 to 99
(or the maximum line length read, which ever is lower).

Ray Ontko, 1999/11/02
*/

#include <stdio.h>

#define COUNT_SIZE 100

main()
{
  int c ;
  int count[COUNT_SIZE] = { 0 } ;
  int max_len = 0 ;
  int pos = 0 ;
  int i ;
  int j ;
  
  while( ( c = getchar() ) != EOF )
  {
    if( c == '\n' )
    {
      if( pos < COUNT_SIZE )
        count[pos] ++ ;
      if( pos > max_len )
        max_len = pos ;
      pos = 0 ;
    }
    else
      pos ++ ;
  }
  
  for( i = 0 ; i <= max_len && i < COUNT_SIZE ; i ++ )
  {
    printf( "%2d "  , i ) ;
    for( j = 0 ; j < count[i] ; j ++ )
      putchar( '*' ) ;
    putchar( '\n' ) ;
  }
  
  putchar( '\n' ) ;
  printf("Maximum length = %d\n" , max_len ) ;
}
