0% found this document useful (0 votes)
112 views

Write A Program To Count Vowels in A File Using File Handling

This C program counts the number of vowels and consonants in a text file. It takes the file path as a command line argument, opens the file, then reads through it character by character. It increments the vowel count variable if the character is a vowel, or the consonant count variable if it is not a vowel. After reaching the end of the file, it prints out the number of vowels found.

Uploaded by

research321
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Write A Program To Count Vowels in A File Using File Handling

This C program counts the number of vowels and consonants in a text file. It takes the file path as a command line argument, opens the file, then reads through it character by character. It increments the vowel count variable if the character is a vowel, or the consonant count variable if it is not a vowel. After reaching the end of the file, it prints out the number of vowels found.

Uploaded by

research321
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

//Write a Program to Count Vowels in a File

Using File Handling



#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();
}

You might also like