/* File: count3.c
By: Tep Dobry
Date:
*/
/* This is a short program to count the number of characters
and lines in a file using getchar() */
#include <stdio.h>
#include "chrutil.h"
main()
{ int c_count = 0;
int l_count = 0;
char ch;
/* while there are more characters */
while((ch = getchar()) != EOF)
{ /* count the character */
c_count = c_count + 1;
/* if the character is a newline - count the line */
if(ch == '\n') l_count = l_count + 1;
}
/* print the results */
printf("There were %d characters in the file\n",c_count);
printf("There were %d lines in the file\n",l_count);
}