/*																																			*
 * lc - A command line utilty that counts the number of lines in a file *
 * Author - Mike Farrell																								*/


/*Includes*/
#include <stdio.h>

/*Main*/
int main(int argc, char *argv[])
{
  FILE *f;											/*File pointer for file access*/
  char buf[512];                /*512 character buffer (maximum column size)*/
  unsigned int line_count = 1;  /*Line count storage*/
  int i;												/*For loop counter*/
  char no_return = 0;           /*Skip return character at the end*/

  for(i = 1; i < argc; i++)
  {
    if(strcmp(argv[i], "--noreturn") == 0)
    {
      no_return = 1;
      continue;
    }
      
    /*Open each file*/
    f = fopen(argv[i], "r");
    if(!f)
    {
      printf("Error opening file!!\n\n");
      return 1;
    }

    /*Count number of lines*/
    while(fgets(buf, 512, f))
      line_count++;

    /*Close the file*/
    fclose(f);
  }

  /*Print out total lines*/
  if(argc > 1)
    printf("Total Lines:  %u%s", line_count, ((no_return) ? "" : "\n"));

  return 0;
}


