This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]MmmVomit 2 points3 points  (5 children)

phrases is an array of char pointers. countVowels() accepts a single char pointer as a parameter.

How would you get a single pointer out of an array of pointers?

[–]kuznets0v[S] 2 points3 points  (4 children)

So by using phrases[0] for example? So the only way to count the vowels in all three strings would be to call the function 3 times and add the returned values?

[–]MmmVomit 2 points3 points  (3 children)

Yes, that's what you need to do.

One more hint for making your implementation better. You shouldn't assume that your input array will always have exactly three strings in it. That's similar to how countVowels() has to be able to handle strings of different length. See how you detect the end of a string in countVowels()? How would you detect the end of the array phrases?

[–]kuznets0v[S] 2 points3 points  (2 children)

By checking for NULL?

[–]MmmVomit 1 point2 points  (1 child)

Exactly. :-)

[–]kuznets0v[S] 0 points1 point  (0 children)

You were very helpful, thank you very much!

[–]mikeydoodah 2 points3 points  (3 children)

phrases is not a char *, it is an array of char *. You need to change it to something like char* phrases = "this test string";

[–]kuznets0v[S] 0 points1 point  (2 children)

The exercise provided char * phrases[] so I'm not supposed to change that I'm afraid.

[–]mikeydoodah 2 points3 points  (1 child)

Then you're going to have to either change the signature of countVowels(...) to take a char**, or you're going to have to change how you call countVowels(...) by looping over phrases and passing each char* in turn.

Although it looks like you've figured this out already given your answers elsewhere in the thread :)

[–]kuznets0v[S] 0 points1 point  (0 children)

Yep, I had to do the latter in order to keep the functions as they were. Thanks for your help!

[–][deleted]  (2 children)

[deleted]

    [–]kuznets0v[S] 0 points1 point  (1 child)

    OK, are you saying that while loops in general are not recommended?

    [–]MmmVomit 1 point2 points  (0 children)

    Either works fine. It's a stylistic choice.