#include <stdio.h>
#include <stdlib.h>
/* #include <ctype.h> */
#include "getCharacter.h"

int 
getCharacters(FILE *source,int option)
{
  /* printf("%d\n",option); */
  
  unsigned int lines=0;
  unsigned int bytes = 0;
  unsigned int words = 0; 
  
  char ch;
  char tmp = ' '; /* temp buffer, initialized to a known condition */

while((ch = fgetc(source)))
    {
      /* printf("%c", ch); */
      if (ch == EOF)
	{
	  if (tmp != ' ' && tmp != '\n')
	    {
	    words++;
	  /* printf("_WORDS++_"); */
	    }
	  /* printf("_BREAK_"); */
	  break;
	}
      
      bytes++; 
      if (ch == '\n')
	{
	  lines++;
	  /* printf("_LINES++_");  */
	}
      
      if (ch == ' ' && (tmp != ' ' && tmp != '\n'))
	{
	  words++;
	  /* printf("_WORDS++_"); */
	}
      if (ch == '\n' && (tmp != '\n' && tmp != ' '))
      	{
      	  words++;
      	  /* printf("_WORDS++_");    */
      	}
      tmp = ch;
    }
 
 /* fprintf(stdout, "%s: ", source); */
 switch (option)
   {
   case 0:
     fprintf(stdout,"%i %i %i\n", lines, words, bytes);
     break;
   case 1:
     fprintf(stdout, "%i\n", bytes);
     break;
   case 2:
     fprintf(stdout, "%i\n", lines);
     break;
   }
  /* fprintf(stdout ,"EOF Recieved\n"); */
  /* fprintf(stdout ,"No. of bytes: %d\n", bytes); */
  /* fprintf(stdout ,"No. of WORDS: %d\n", words); */
  /* fprintf(stdout ,"No. of lines: %d\n", lines); */
  return 0;
}

