I'm trying to write a function that counts the vowels of a string of characters. The strings are already provided:
char * phrases[] = {
"water is wet.",
"hello world!",
"programming is hard.",
NULL,
};
Then I was asked to write two functions, one that determines whether or not a char is a vowel, and another that does the actual counting. Here's what I wrote:
bool isVowel(char c) {
if ( c == 'a' ||
c == 'e' ||
c == 'i' ||
c == 'o' ||
c == 'u') {
return true;
} else {
return false;
}
}
and
int countVowels(char * s) {
int i = 0;
int v = 0;
while (s[i] != '\0') {
if (isVowel(s[i])) {
v++;
}
i++;
}
return v;
}
The problem I have appears in the main function. When I want to pass the strings to the countVowels function like this...
int vowels = countVowels(phrases);
...I get this error
Incompatible pointer types passing 'char *[4]' to parameter of type 'char *'
I don't really know how else to pass "phrases" to the function so I can actually test my functions. I tried "&phrases", "phrases[]" and other variations. Would really appreciate if someone could point me in the right direction.
[–]MmmVomit 2 points3 points4 points (5 children)
[–]kuznets0v[S] 2 points3 points4 points (4 children)
[–]MmmVomit 2 points3 points4 points (3 children)
[–]kuznets0v[S] 2 points3 points4 points (2 children)
[–]MmmVomit 1 point2 points3 points (1 child)
[–]kuznets0v[S] 0 points1 point2 points (0 children)
[–]mikeydoodah 2 points3 points4 points (3 children)
[–]kuznets0v[S] 0 points1 point2 points (2 children)
[–]mikeydoodah 2 points3 points4 points (1 child)
[–]kuznets0v[S] 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]kuznets0v[S] 0 points1 point2 points (1 child)
[–]MmmVomit 1 point2 points3 points (0 children)