/* voteReader.cpp   Demonstrate reading data from a file
   P. Conrad, 9/23/04, CISC105, Fall 2004 */

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

int main(void)
{
  FILE *infile;
  char state[3];  /* 2 for the state, one to terminate the string */
  char candidate;
  int electoralVotes;

  int result; /* for result of scanf */

  infile = fopen("electoralVotes.dat","r");

  if (infile==NULL)
    {
      fprintf(stderr,"File could not be opened.  Sorry about that.\n");
      exit(-1);
    }
  
  result = fscanf(infile,"%s\t%c\t%d",&state, &candidate, &electoralVotes);
  while (result != EOF)
    {
      printf("State=%s Candidate=%c Votes=%d\n",
	      state, candidate, electoralVotes) ;
      result = fscanf(infile,"%s\t%c\t%d",&state, &candidate, &electoralVotes);
    }

  printf("All done with all lines in the file\n");
  return 0;
}

