Count the no of lowercase letters in a text file bca.txt in C

Write a program in C to count the no of lowercase letters in a text file bca.txt


This program reads one character at a time by using fgetc() function until the EOF (end of file) returns. Then it checks whether the current character is lowercase or not. If it is a lowercase letter it increments the value of c by 1. It also displays the contents of file named bca.txt. And finally print the total number of lowercase letters present in the file, which is the main purpose to write the program

Program

  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4.  {
  5.   FILE *fptr;
  6.   char ch;
  7.   int c=0;
  8.   if((fptr=fopen("bca.txt","r"))==NULL)
  9.    printf("File doesn't exist\n");
  10.   else
  11.    {
  12.     while((ch=fgetc(fptr))!=EOF)
  13.      {
  14.       if(ch>=97&&ch<=122)
  15. c++;
  16.       printf("%c",ch);
  17.      }
  18.    }
  19.    printf("\nTotal lowercase letter in bca.txt file is %d",c);
  20.   fclose(fptr);
  21.  }

Sample Text (bca.txt)

My name is Gaurav Pali.
My higher qualification is MCA

Sample Text (bca.txt) SCREENSHOT




PROGRAM SCREENSHOT



OUTPUT




Popular posts from this blog

IGNOU Solved Assignment 2023-24 | BCS-012 Basic Mathematics BCA(I)012/Assignment/2023-24

MCS-051 : ADVANCED INTERNET TECHNOLOGIES | 1. (a) Write a web application using JSP and JDBC that takes a bank account number as input and displays the account balance.

MCS054 TEE June 2021 Q1(b) | Bisection Method