+ 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; }
6 ответов
+ 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
+ 3
Thank you very much for helping me 😊
+ 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.
+ 2
302 error is coming bcz I copied it from my pc compiler and paste it to Mobile compiler.
+ 2
Remove all those spaces where it pointing invalid characters. Or rewrite same code. Then it works fine ...
+ 1
Ok👍