by Dinesh Thakur Category: C Programming (Pratical)

In this program user ask to count the line in a file. User declares the required variable for storing the value and some are of pointer type. User put the method for opening file and using if-else condition to vary the condition if content is not found then terminate else with the use of while condition read the content until (ch != EOF). Then varying the condition the counted lines are on the display on the screen. In the end a method in end to close the file.

Problem Statement:

This is C Program to count out the lines on a file.

  1. Declaring the variables.
  2. Using control statements.
  3. Display result on the screen.

Here is C source code for counting the lines on a file. The output of this program shown below. 


void main()
     FILE *p;
     char ch;
     int l=1;
               printf("File not Found");
                                printf("Lines in a file are= %d",l);

Count the Lines in a File

About Dinesh Thakur
