+ 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 Antworten
+ 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