//===================================================== file = runlen.c =====
//=  Program to compute run lengths for a stream of strings (e.g., values)  =
//===========================================================================
//=  Notes:                                                                 =
//=    1) Input from input file "in.dat" to stdin (see example below)       =
//=        * No comments are allowed                                        =
//=    2) Output is to stdout                                               =
//=-------------------------------------------------------------------------=
//= Example "in.dat" file:                                                  =
//=                                                                         =
//=    12                                                                   =
//=    abc                                                                  =
//=    abc                                                                  =
//=    12                                                                   =
//=    12                                                                   =
//=    12                                                                   =
//=     1                                                                   =
//=     2                                                                   =
//=     3                                                                   =
//=     3                                                                   =
//=     3                                                                   =
//=-------------------------------------------------------------------------=
//= Example output (for above "in.dat"):                                    =
//=                                                                         =
//=   ------------------------------------------------ runlen.c -----       =
//=       1                                                                 =
//=       2                                                                 =
//=       3                                                                 =
//=       1                                                                 =
//=       1                                                                 =
//=       3                                                                 =
//=   ---------------------------------------------------------------       =
//=-------------------------------------------------------------------------=
//=  Build: gcc runlen.c, bcc32 runlen.c, cl runlen.c                       =
//=-------------------------------------------------------------------------=
//=  Execute: runlen < in.dat                                               =
//=-------------------------------------------------------------------------=
//=  Author: Kenneth J. Christensen                                         =
//=          University of South Florida                                    =
//=          WWW: http://www.csee.usf.edu/~christen                         =
//=          Email: christen@csee.usf.edu                                   =
//=-------------------------------------------------------------------------=
//=  History: KJC (08/11/00) - Genesis                                      =
//===========================================================================

//----- Include files -------------------------------------------------------
#include <stdio.h>                 // Needed for scanf() and printf()
#include <string.h>                // Needed for strcmp()

//===========================================================================
//=  Main program                                                           =
//===========================================================================
void main(void)
{
  int      run_len;                  // Run length variable
  char     in_string[1024];          // Input string
  char     last_string[1024];        // Last string

  // Output a banner
  printf("------------------------------------------------ runlen.c -----\n");

  // Loop to compute run lengths
  run_len = 1;
  scanf("%s \n", last_string);
  while(1)
  {
    scanf("%s \n", in_string);

    if (strcmp(in_string, last_string) == 0)
    {
      run_len++;
      if (feof(stdin))
      {
        printf("  %d \n", run_len);
        break;
      }
    }
    else
    {
      printf("  %d \n", run_len);
      if (feof(stdin)) break;
      run_len = 1;
    }

    strcpy(last_string, in_string);
  }
  printf("---------------------------------------------------------------\n");
}

