by Dinesh Thakur

In this program integer type variables declare (vowel,Consonent) and pointer of file (FILE *fp1;). And control statements also used if the given situation is not true than the arguments will be insufficient else it will go on. Nested if statements also come in use the next move is to if file pointer is null then source will not open. While condition tells the (ch!EOF) not equal to End of File. If condition used with the OR (!!) operator. This Will checks out the given characters match the condition. Then it’s Vowel else consonant. And in the last move it will be counted as result.

Problem Statement:-
Here in the program user has to count the Vowel with the use of file handling Concept.

  1. Checks out The Given Arguments.
  2. Using the Control Statements.
  3. Applying Required Statements.
  4. Display Result on Screen.

The C program is successfully compiled. The program output is also shown below.

#include<process.h>

#include <stdio.h>
        void main(int argc,char *argv[])
 {
         
          FILE *fp1;
          int vowel=0,consonant=0;
          char ch;
          clrscr();
          if(argc!=2)
            {
                     printf("Insufficient Arguments");
                     exit(0);
            }
          fp1=fopen(argv[1],"r");
          if(fp1==NULL)
            {
                    printf("Source can't be opened");
                    exit(0);
            }
          ch=fgetc(fp1);
          while(ch!=EOF)
                {
                       if((ch=='a')||(ch=='A')||(ch=='e')||(ch=='E')||(ch=='i')||(ch=='I')||(ch=='o') ||(ch=='O')||(ch=='u')||(ch=='U'))
                         {
                               vowel++;
                          }
                      else
                         {
                             consonant++;
                         }
                             ch=fgetc(fp1);
                }
                             printf("\n Number of vowels are = %d",vowel);
                             getch();
}

Write a Program to Count Vowels in a File Using File Handling

Follow us