/* readData.c   P. Conrad 10/24/05 */
/* read water polo data into an array */


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

#define MAXLINE 1024 /* maximum characters on one line */

#define FILENAME "data.txt"

int main(void)
{
  int i; /* for the for loop */

  FILE *infile;
  char buffer[MAXLINE];
  char *result; /* return value from fgets */
  int count; /* the number of lines read from the file */

  int thisNumber;

  /* declare array */

  int goalsPerPlayer[10]; /* goals scored by each player recently */

  /* open the input file */
  

  infile = fopen(FILENAME,"r");
    
  if (infile == NULL)
    {
      perror("opening " FILENAME); /* no comma! */

      fprintf(stderr,"Could not open " FILENAME "\n");
      exit(1);
    }
  
  /* actually read data from the file */

  count = 0;
  
  /*  fgets reads one line from the file */

  result = fgets(buffer, MAXLINE, infile);
  while (result != NULL)
    {
      printf("I read this from the file: |%s|  \n",buffer);

      thisNumber = atoi(buffer); /* converts from ASCII to integer */

      goalsPerPlayer[count] = thisNumber;
      count ++;

      result = fgets(buffer, MAXLINE, infile);
    }

  /* When all done with the file, print a summary of results */

  printf("I read %d lines from the file\n", count);

  for (i=0; i<count; i++)
    printf("goals for player %d were %d \n", i, goalsPerPlayer[i]);
  
  /* find the total number of goals scored by all players */
  
  {
    int totalGoalsScored = 0;
    int i;
    
    for (i=0; i < count ; i++)
      totalGoalsScored += goalsPerPlayer[i] ;

    printf("total goals scored = %d\n",totalGoalsScored);

  }
  


  /* find how many goals the best player(s) scored */


  /* find the player(s) who scored the most goals */




  /* find the average number of goals scored by all players */




  return 0;
}











