Find no of vowels in string? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 3

Find no of vowels in string?

Why my output is coming 0? #include<stdio.h> #include<string.h> int countvowels(char str[]); int main() { Ā  Ā  char str[]="helloworld"; Ā  Ā  printf("vowels are %d",countvowels(str)); Ā  Ā  return 0; } int countvowels(char str[]) { Ā  Ā  int count = 0; Ā  Ā  for (int i = 0;i !='\0';i++) Ā  Ā  { Ā  Ā  Ā  Ā  if (str[i] =='a' || str[i] =='e' || str[i] =='i' || str[i] =='u' || str[i] =='o' ) Ā  Ā  Ā  Ā  { Ā  Ā  Ā  Ā  Ā  Ā  count++; Ā  Ā  Ā  Ā  } Ā  Ā  } Ā  Ā  Ā  Ā return count; }

13th Mar 2022, 8:47 AM
SHÅŖBHƃM
SHÅŖBHƃM - avatar
6 Respostas
+ 3
Check the condition inside for loop it should be str[i] != '\0' instead of i != '\0' your code is also showing error stray 302 which means it has some extra hidden characters. these stray characters are causing errors. don't copy codes from external resources
13th Mar 2022, 9:21 AM
NonStop CODING
NonStop CODING - avatar
+ 3
Thank you very much for helping me šŸ˜Š
13th Mar 2022, 4:36 PM
SHÅŖBHƃM
SHÅŖBHƃM - avatar
+ 2
You are using loop condition i !='\0' which is Initially true, so loop not starting.. Actually you need str[i] != '\0'. Your code have invalid characters, remove all. may you copied it net source. Hope it helps.
13th Mar 2022, 9:22 AM
Jayakrishna šŸ‡®šŸ‡³
+ 2
302 error is coming bcz I copied it from my pc compiler and paste it to Mobile compiler.
13th Mar 2022, 4:38 PM
SHÅŖBHƃM
SHÅŖBHƃM - avatar
+ 2
Remove all those spaces where it pointing invalid characters. Or rewrite same code. Then it works fine ...
13th Mar 2022, 4:55 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
OkšŸ‘
14th Mar 2022, 3:56 AM
SHÅŖBHƃM
SHÅŖBHƃM - avatar