C Programming File Handling | Counting Total characters in *files

Write a Modular C Programming code for Counting Total characters in *files

*The file should be saved in (1.txt) this Format in the location of this c file.
Below is the content of File:

Facts Prime is the #1 resource that provides not only the facts on science and ancient history.
but also is being involved in gathering a variety of codes in C programming for 
data structures and many more. This page has a unique feel,  
with efforts of constructed action figures representing the co-founders.

Refer To Notes:  Notes: File Handling in C programming | Operations in Files

CODE:

#include<stdio.h>
#include<stdlib.h>
/*
    Modular Program to count number of characters in a file
*/


#include
#include
long long int count(FILE *);
int main()
{
    FILE *fp1;
    fp1 = fopen("1.txt","r");
    if(fp1==NULL)
    {
        perror("");
        exit(0);
    }
    c = count(fp);
    printf("%lld\n",c);
    fclose(fp);
    return 0;
}

long long int count(FILE *fp)
{
    long long int c = 0;
    char ch;
    while((ch=getc(fp))!=EOF)
        c++;
    return c;
}

OUTPUT

308

Process returned 0 (0x0)   execution time : 369.409 s
Press any key to continue.

 

Refer : C Programming HackerRank all solutions for Loops | Arrays | strings

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University

 

 

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!