/***************************************************************************
 *  Columbia University Introduction to Computer Programming in C COMS 1003
 *  Calculate average, min, and max of a set of scores supplied on stdin
 *
 *  Copyright (C) 2005 Michael E. Locasto
 *
 *  All rights reserved.
 *
 * $Id: calcscores.c,v 1.1 2005/10/25 15:09:15 locasto Exp $
 **************************************************************************/

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

#define   MAX_LINE_LENGTH    80
#define   MAX_SCORES         60

/**
 * This program XXX
 *
 * 
 */
int main(int argc, char* argv[])
{
   int c = 0;
   //int x = 0;
   char line[MAX_LINE_LENGTH] = {0};
   int i = 0;
   int scores[MAX_SCORES] = {0};
   int num_scores = 0;
   
   while(EOF!=(c=getchar()))
   {
      if(!isspace(c) && i<(MAX_LINE_LENGTH-1))
      {
         line[i++]=c;
      }else if(isspace(c)){
         //NULL terminate the string
         line[i]='\0'; 
         if(num_scores < MAX_SCORES)
         {
            scores[num_scores] = atoi(line);
            printf("scores[%2d] = %3d\n", num_scores, scores[num_scores]);
            ++num_scores;
         }
         memset(line, 0, MAX_LINE_LENGTH);
         i = 0;
      }

      /* Echo input to output */
      //x = putchar(c);
      /*
      if(EOF==x)
      {
         printf("\n--- OUTPUT ERROR ---\n");
      }
      */
   }
   printf("We have %d score%sin the class.\n",num_scores,
          (num_scores==1)? " " : "s ");
   return 0;
}
