I just want to print highest numbered vowel.
For ex: the cat is the cat. In this sentence,
the vowel a is repeated 2 times
the vowel e is repeated 2 times
the vowel i is repeated 1 times
the vowel o is repeated 0 times
the vowel u is repeated 0 times
I just want to see a and e in the console.
Here is the code.
void vowel(char st2[]){
char vow[]="aeiou"; //vowel
int i=0,j=0,count=0;
while(vow[i]!='\0'){ //loop until sentence ends
count=0;
for(j=0;j<strlen(st2);j++)
{
if(st2[j]==vow[i]){ //increment the counter by one if one letter in the sentence is equal to the vowels
count++;
}
}
printf("the vowel %c is repeated %d times\n",vow[i],count);
i++;
}
}
counts, one for each vowel, and do not print anything in the while loop. After having the count of each vowel in thecountsarray, print out only the index corresponding to the highest number.strlenin your loop test. It needlessly slows your code. Since you're using C, performance must be an issue, so don't write code like this. Think about it. If you were doing it by hand, would you count the length of the string each and every time? Of course not. So why is your code doing it? It makes no sense.