Horje
get file ligne count c Code Example
get file ligne count c

#include <stdio.h>

int main()
{

    FILE *fileptr;
    int count_lines = 0;
    char filechar[40], chr;


    printf("Enter file name: ");
    scanf("%s", filechar);
    fileptr = fopen(filechar, "r");
   //extract character from file and store in chr
    chr = getc(fileptr);
    while (chr != EOF)
    {
        //Count whenever new line is encountered
        if (chr == 'n')
        {
            count_lines = count_lines + 1;
        }
        //take next character from file.
        chr = getc(fileptr);

    }
    fclose(fileptr); //close file.
    printf("There are %d lines in %s  in a file\n", count_lines, filechar);
    return 0;
}




C

Related
national festivals of india in hindi Code Example national festivals of india in hindi Code Example
suma de digitos Code Example suma de digitos Code Example
remove language from jupyter notebook Code Example remove language from jupyter notebook Code Example
The fscanf and fprintf functions Code Example The fscanf and fprintf functions Code Example
Program to Find Swap Numbers Using Temporary Variable Code Example Program to Find Swap Numbers Using Temporary Variable Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8