Counting the number of characters in a file || File handling || C programming
In this program, we are going to count the number of characters in a file with the help of C Programming Language.

 


#include <stdio.h>
#include <windows.h>

void main()
{

    FILE *fp;
    char c;
    int noc = 0, nol = 0, nob = 0;

    fp = fopen("FileDisplay.C", "r");

    if (fp == NULL)
    {
        printf("File can't be opened");
        a return;
    }

    while ((c = fgetc(fp)) != EOF)
    {
        putchar(c);
        noc++;
        switch (c)
        {
        case ' ':
        case ' ':
            nob++;
            break;
        case ' ':
            nol++;
        }

        sleep(20);
    }

    fclose(fp);

    printf("No. of characters = %d", noc);
    printf("No. of lines = %d", nol);
    printf("No. of white spaces = %d", nob);

    getch();
}

//.....coded by ANANYA MAURYA

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post