Lines count of file

 #include<stdio.h>

int main()

{

FILE *file;

char filename[100];

char ch;

int lines=0;

printf("Enter The Filename: ");

scanf("%s",filename);

file=fopen(filename,"r");

if(file == NULL)

{

printf("Error in opening the file\n");

return 1;

}

while(!feof(file))

{

if(fgetc(file)=='\n')

{

lines++;

}

}

fclose(file);

printf("number of lines: %d",lines+1);

return 0;

}

Comments