PROGRAM FOR FINDING OUT NUMBER OF LINES IN A FILE | CODE WITH SHARAD

PROGRAM FOR FINDING OUT NUMBER OF LINES IN A FILE

Written by Sharad Raj on 24th of May, 2018

C LANGUAGE PROGRAMS   FILE HANDLING PROGRAMS

PROGRAM CODE

#include <stdio.h>
int main()
{
FILE *fp;
int count=0;
char fname[20],c_store;
printf("Enter the file name : ");
scanf("%s",fname);
fp = fopen(fname, "r");
if (fp==NULL)
{
printf("Cannot open file %s \n", fname);
exit(0);
}
c_store = getc(fp);
while (c_store != EOF)
{
if (c_store == '\n')
{
count++;
}
c_store = getc(fp);
}
fclose(fp);
printf("\nFILE NAME :%10s \nNUMBER OF LINES : %3d\n", fname, count);
return 0;
}


Comments


Contact