Program to write to a file and display the vowel which occurred the most often. If you need help comment below
#include<stdio.h>
main()
{
FILE *f1;
char c;
int a,e,i,o,u;
a=0;
e=0;
i=0;
u=0;
o=0;
printf("\nEnter the letters to the file:\n");
f1=fopen("TEXT.txt","w");
while((c=getchar())!='\n')
putc(c,f1);
fclose(f1);
f1=fopen("TEXT.txt","r");
while((c=getc(f1))!=EOF)
{
if(c=='a')
a++;
else if(c=='e')
e++;
else if(c=='i')
i++;
else if(c=='o')
o++;
else if(c=='u')
u++;
}
fclose(f1);
if((a>=e)&&(a>=i)&&(a>=o)&&(a>=u))
printf("\n\n'a'is the vowel which occured the most.\n%d times",a);
if((e>=a)&&(e>=i)&&(e>=u)&&(e>=o))
printf("\n\n'e' is the vowel which occured the most.\n%d times",e);
if((i>=a)&&(i>=e)&&(i>=o)&&(i>=u))
printf("\n\n'i' is the vowel which occured the most.\n%d times",i);
if((o>=a)&&(o>=e)&&(o>=i)&&(o>=u))
printf("\n\n'o'is the vowel which occured the most.\n%d times",o);
if((u>=a)&&(u>=e)&&(u>=i)&&(u>=o))
printf("\n\n'u' is the vowel which occured the most.\n%d times",u);
printf("\n\n");
}
No comments:
Post a Comment