
Patrick B. answered 02/02/20
Math and computer tutor/teacher
#include <stdio.h>
/* returns 1 if the character is a vowel, zero otherwise */
#define isVowel(x) ( ( ( (x)=='A') || ((x)=='a') || ((x)=='E') || ((x)=='e') || ((x)=='I') || ((x)=='i') || ((x)=='O') || ((x)=='o') || ((x)=='U') || ((x)=='u')))
void GO( int argc, char * argv[])
{
char output_filename[255];
FILE * infile = fopen(argv[1],"r");
sprintf(output_filename,"%s%s","VOWELS_",argv[1]);
FILE * outfile = fopen(output_filename,"w");
if (infile != NULL)
{
if (outfile != NULL)
{
char ch='?';
int total_vowel_count=0;
int iLineNum=1;
int iLineVowelCount=0;
while ((ch = fgetc(infile))!= EOF)
{
if (
(isVowel(ch)) || (ch=='\n')
)
{
if (ch !='\n')
{
total_vowel_count++;
iLineVowelCount++;
}
fputc(ch,outfile);
if (ch=='\n')
{
printf(" Line # %d has %d vowels \n",iLineNum++,iLineVowelCount);
iLineVowelCount=0;
}
}
else
{
fputc(' ',outfile);
}
} /* while */
printf("-----------------------------------------\n");
printf(" total # of vowels : %d \n",total_vowel_count);
}
else
{
printf(" ERROR OPENING OUTPUT FILE \n");
}
}
else
{
printf(" ERROR OPENING INPUT FILE \n");
}
fclose(infile);
fclose(outfile);
}
int main(int argc, char * argv[])
{
if (argc==1)
{
printf(" Please specify the name of the input file \n");
printf(" :> VOWELS input.dat \n");
}
else
{
GO(argc,argv);
}
}