Pages

Saturday, September 22, 2018

Count vowels in given file.


C Program to count Vowels in a given file.

This program will read input from "data.txt" file and prints total number of vowels.

#include<stdio.h>
int main()
{
  FILE *fp;
  char ch;
  int cnt=0;

  fp = fopen("data.txt","r");

  if (fp == NULL)
  {
  printf("Can't Open File.");
  exit(1);
  }
  printf("File content is : ");
  ch = fgetc(fp);
  
  while(ch != EOF)
  {
    putchar(ch);
if( ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
        cnt++;
    ch = fgetc(fp);
  }

  printf("\n\nTotal vowels in given file = %d",cnt);
  return 0;
}

Output of Program

File content is : THIS IS TOP C PROGRAMMING PRACTICALS BLOG.

Total vowels in given file = 10


No comments:

Post a Comment