I am confused about counting how many differents vowels are in one word? This is were i got so far... I am saving word by word in the variable word[] and then check char by char whether is vowel or not... but i don't know how to count how many different vowels are in the word? Please help. Thanks in advance.
int i,j,words = 0;
while(fgets(row,MAX,f) != NULL)
{
int flag = 0;
int n = 0;
for(i = 0; i < strlen(row); i++)
{
if(isalpha(row[i]))
{
if(!flag)
{
flag = 1;
}
word[n++] = row[i];
}
else if(flag)
{
flag = 0;
word[n] = '\0';
for(j = 0; j < strlen(word);j++)
{
if(isvowel(word[i]))
{
c = word[i];
}
// i stopped here cause i donno how to check whether the char is different from all the others
}
}
}
}
Okay it seems like the function for counting the different vowels in one word is created manually, but this solution really works and here it is:
As you find each vowel, simple set a flag of an array to note the vowel was found. Then count the number of flags. The trick is to effectively convert
c
(the vowel) into an index - that is where you are stuck.char *strchr(const char *s, int c)
is useful. It locates the first occurrence of(char) c
in the string pointed to bys
. Converting the result to an index for the flag array is then easy.Let's say
'A'
is the same as'a'
for vowel counting.