get file ligne count c

Solutions on MaxInterview for get file ligne count c by the best coders in the world

showing results for - "get file ligne count c"
Mariangel
16 Apr 2017
1
2#include <stdio.h>
3
4int main()
5{
6
7    FILE *fileptr;
8    int count_lines = 0;
9    char filechar[40], chr;
10
11
12    printf("Enter file name: ");
13    scanf("%s", filechar);
14    fileptr = fopen(filechar, "r");
15   //extract character from file and store in chr
16    chr = getc(fileptr);
17    while (chr != EOF)
18    {
19        //Count whenever new line is encountered
20        if (chr == 'n')
21        {
22            count_lines = count_lines + 1;
23        }
24        //take next character from file.
25        chr = getc(fileptr);
26
27    }
28    fclose(fileptr); //close file.
29    printf("There are %d lines in %s  in a file\n", count_lines, filechar);
30    return 0;
31}
queries leading to this page
c file get ligneget file ligne count c