/***************************************************************************
 *  Columbia University Introduction to Computer Programming in C COMS 1003
 *  Echo an input file of scores char by char to the stdout
 *
 *  Copyright (C) 2005 Michael E. Locasto
 *
 *  All rights reserved.
 *
 * $Id: printscores-wrong.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 prints out each character of stdin to stdout
 *
 * 
 */
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()))
   {
      while(!isspace(c) && i<(MAX_LINE_LENGTH-1))
      {
         line[i++]=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);
      
      /* Echo input to output */
      //x = putchar(c);
      /*
      if(EOF==x)
      {
         printf("\n--- OUTPUT ERROR ---\n");
      }
      */
   }
   printf("We have %d scores in the class.\n",num_scores);
   return 0;
}
