+ 4

[SOLVED] Vowel counter code coach

You need to make a simple program that counts the number of vowels in a sentence. My code doesn't pass the last test and I can't figure out the reason. Ps: I tried to declare the sentence array with a length of 200 characters and it doesn't work. Another possible bug is the condition of the outer for that may be broken by a new line. But I don't think that Sololearn is doing these kind of tests on an 'easy" code coach. https://code.sololearn.com/cIZ3yZFBKyfa/?ref=app

14th Nov 2020, 7:05 PM
Davide
Davide - avatar
9 Answers
+ 6
Don't see any problems here. Can it be that the sentence in the last test is larger than 200 characters? Is something about the sentence size told in the problem statement? Did you try to put for example 10**7 there? (both into array size and fgets) (sorry i cannot open the challenge because i am a greedy freeloader)
14th Nov 2020, 8:12 PM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar
+ 5
Davide glad that you found the problem. It is a common case, when we do the change in one place and forget to do the corresponding change in another, so it's useful to write code in the way that every change has to be done only once (that is one of the reasons for "Don't Repeat Yourself" maxim). In this case you can either declare size of the array as a constant , and use the constant both in array declaration and fgets, or put sizeof(sentence) in fgets (for the last case you should be also careful of array to pointer decay, when size is lost, but here it is not a problem).
14th Nov 2020, 8:26 PM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar
+ 4
Volodymyr Chelnokov OMG šŸ˜­šŸ˜­šŸ˜­ I am so dumb šŸ˜­šŸ˜­šŸ˜­ When I tried with 200 I haven't corrected the fgets šŸ˜­šŸ˜­šŸ˜­ I am so sorry šŸ˜” Anyway thanks so much to you and everyone who tried to help me!šŸ¤—šŸ¤—šŸ¤—šŸ¤—šŸ¤—
14th Nov 2020, 8:19 PM
Davide
Davide - avatar
+ 3
CHERIEF Houcine Abdelkader that's a lie. Don't lie to me šŸ˜” In any case the increment is executed at the end of the loop
14th Nov 2020, 7:19 PM
Davide
Davide - avatar
+ 3
NotAPythonNinja yes I had this idea as well, but checking the text of the problem I saw it specifies only aeiou in lowercase and uppercase Thanks for trying anyway šŸ˜­šŸ¤—
14th Nov 2020, 7:41 PM
Davide
Davide - avatar
+ 3
Volodymyr Chelnokov you are right, constants are a nice thing šŸ¤—
14th Nov 2020, 8:34 PM
Davide
Davide - avatar
+ 2
CHERIEF Houcine Abdelkader is there a reason for that?
14th Nov 2020, 7:12 PM
Davide
Davide - avatar
+ 2
NotAPythonNinja I read it many times, it just says to count the vowels šŸ˜­ and that is what I do šŸ˜­
14th Nov 2020, 8:07 PM
Davide
Davide - avatar