0
In code coach expected output is obtained but test cases are failing why?
For this pig latin problem in code coach https://www.sololearn.com/coach/16?ref=app This is my solution. https://code.sololearn.com/c83rt5WaouPQ/?ref=app The output is exact but the test cases are failing. Please explain why and what's wrong? https://code.sololearn.com/c83rt5WaouPQ/?ref=app
4 ответов
+ 1
Because the value of strlen() is changing with each call. As an example, consider a sentence with three words, the last having two characters. Handtracing shows that 'i' would equal two for the third word, and so would strlen(), resulting in a failed condition.
Basically you risk not printing some words. Consider a different condition for the loop, for example based on the null character to distinguish written and unwritten arrays.
+ 3
Since you are scanning each character individually, the null character is not automatically added at the end of the string, rendering any calls to strlen() faulty. Initialize the array with null characters before taking the input, or use a proper way of retrieving the input, such as fgets().
Furthermore, 20 characters might not be enough for all test cases. Consider a bigger array.
And last, since you are printing one character ahead, you need to make sure not to print anything that lies after the actual string. For example, printing a null character, although not visible, results in a failure due to the extra character.
+ 1
Thank you very much! All the cases have been solved.
0
Improved the code a little bit (actually a lot). Now 4 cases succeeded and the last one is failing