#include <stdio.h>

/* Pointless program to count lines beginning with 'a' - there is a
test file called file.txt in this directory*/

enum {
    MAX_LEN = 256
};

int main()
{
    FILE *fptr;               /* A file pointer holds information about a file*/
    char read_line[MAX_LEN];  /* String to hold line we read */
    int count= 0;             /* Count the number of letter a s */
    int lines= 0;             /* Count the number of lines */


    /* Try to open a file called file.txt - exit on error*/
    fptr= fopen ("file.txt","r");
    if (fptr == NULL) {
        printf ("Unable to open file\n");
        return -1;
    }

    /* Loop round the lines of the file, reading from the file
    pointed to by fptr - count 'a's and lines */
    while (fgets(read_line, MAX_LEN, fptr) != NULL) {
        if (read_line[0] == 'a') {
            count++;
        }
        lines++;
    }
    fclose(fptr);
    printf ("%d lines from %d begin with a\n",count, lines);
    return 0;
}

