PROBLEM:
Write a C program that prompts the user to enter a string of characters terminated by ENTER key (i.e. ‘\\n’) and then count the total number of the occurrence o
while((c = getchar()) != '\n')
{
if((counter[i] == 'a' || counter[i] == 'e' || counter[i] == 'i' || counter[i] ==
'o' || counter[i] == 'u') ||(counter[i] == 'A' || counter[i] == 'E' || counter[i] ==
'I' || counter[i] == 'O' || counter[i] == 'U'))
{
for(i = 0; i < 5; i++)
{
if(c == 'a' + i)
counter[i] = counter[i] + 1;
}
}
}
I feel the logic in this code may be wrong because, you have initialized your counter[0] with 0 and then you are comparing it with 'a' or 'A' but not the char c, so use
while((c = getchar()) != '\n')
{
if(c == 'a' || c == 'A')
{
i = 0;
counter[i] =+ 1;
}
else if( c == 'i' || c == 'I' )
{
i = 1;
counter[i] =+ 1;
}
...//and so on
}