The C program to count number of vowels in a file.

#include <stdio.h>
#include <string.h>
int main(int argc,char *argv[])
 {
  FILE *fptr;
  int vowels=0,consonants=0;
   char c;
  if(argc!=2)
   {
    printf("Not sufficient Arguments Given Try Again");
    exit(0);
   }
   fptr1=fopen(argv[1],"r");
   if(fptr1==NULL)
   {
     printf("OOPs! Source can't be opened");
    exit(0);
   }
   c=fgetc(fptr1);
   while(c!=EOF)
   {
    if((c=='A')||(c=='a')||(c=='e')||(c=='E')||(c=='I')||(c=='i')||(c=='o') ||(c=='O')||(c=='U')||(c=='u'))
   {
     vowels++;
   }
   else
   {
     consonants++;
   }
   c=fgetc(fptr1);
   }
   printf("\n Number of vowels are = %d",vowels);
   printf("\n Number of consonants are = %d", consonants);
   return(0);
  }
  return 0;
 }


our file name is demo.c
Output
demo.exe sample.txt
Number of vowels are =7
Number of consonants are =8
The program given above, Counts the number of vowels and consonents in a given file entered by the user .


Previous Topic:-->> Update file contents in C. || Next topic:-->>Micro substitution in c.