+ 1

Descending Word

I don't know where's the problem I want to sort the words in descending order but when I input : D B c a the output should be : D c B a can someone fix it? https://code.sololearn.com/cg6ez6Zw0fVb/#c

18th May 2019, 3:30 PM
SSyahrir
SSyahrir - avatar
3 odpowiedzi
+ 2
I guess the problem could be because the code try to change the case of the input string to lowercase, but it's not doing what it was supposed to do. It converts `s[i]` to lowercase, but the character being converted isn't necessarily be the first one, due to `i` changes on each loop iteration. Because the input string isn't properly converted to lowercase, the `strcmp` fails to compare as we want it to. Because some input still are in their original case (uppercase). (Edit) `tolower` returns lowercase version of its argument, so the call for `tolower(s[i]);` didn't have any effect.
18th May 2019, 7:19 PM
Ipang
+ 1
It's working fine for me. This is what I use as input. 4 BOOK Chair Apple Wood And the output is the expected one.
18th May 2019, 5:12 PM
Diego
Diego - avatar
0
I'm sorry I write the wrong test case I mean D B c a should be D c B a
18th May 2019, 6:43 PM
SSyahrir
SSyahrir - avatar