I'm trying to solve a problem where based on a k number which is the minimum number of vowels will print all the words with at least k vowels. So, for example having:
Input: with k=2
cars are...really nice
Output:
are
really
nice
I think i'm pretty close but i'm having a few issues with saving the words and than checking the number of vowels. Here is the code:
int is_letter(char c) {
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
return 1;
return 0;
}
int main(){
ifstream fin("dateTest.in");
char s[250];
char word[250];
int k;
fin>>k;
int nrVowels=0;
while(fin>>s){
int n = strlen(s);
int have_word = 0;
for (int i = 0; i < n; ++i){
if (is_letter(s[i])){
have_word = 1;
word[i]+=s[i]; //Here i'm having some problems
}else if (have_word == 1) {
for(int i=0; i<strlen(word); i++){
if (word[i] == 'a' || word[i] == 'e' || word[i] == 'o' || word[i] == 'i' || word[i] == 'u'){
nrVowels++;
if(nrVowels >= k){
cout<<word;
}
}
}
have_word = 0;
//Here i should somehow reset the word variable?
}
}
}
}
At first i created a function that checks if a character is a letter. After that i have a while which iterates through all the words from a file, a for which verifies every word and if it is a word, that word should be saved in another variable which i'm doing wrong:( and if it's not finding another word it means that the word ended and it should check for vowels and then print the word if it has a minimum of k vowels. My problem is that the way i save the word it's not working and at the end i should somehow reset the word variable so that another word will be saved there.