+ 1

Military Time - Help!

I canā€™t figure out how to satisfy test case 5! It seems like Iā€™ve tried everything. Anything I might be missing? https://code.sololearn.com/c8dHxqq34NU8/?ref=app

29th Jan 2022, 12:58 AM
Sean
9 Answers
+ 3
Hey Sean .... It's your use of %i. Change them all to %d & it works!
29th Jan 2022, 8:56 AM
HungryTradie
HungryTradie - avatar
+ 3
I messed about with some extra brackets at your if && - || statements, no pass. I played with minutes = 0 to be minutes = 00, no pass. I then tried your code with: *str="12:00 PM"; I got 00:00 An then with *str="12:00 AM"; I got 00:00 Could that be case 5? EDIT: oops, that was something I did to your code. Doesn't do it now.
29th Jan 2022, 3:46 AM
HungryTradie
HungryTradie - avatar
+ 3
I noticed you use digit for malloc, why not šŸ‘‰digit*sizeof(ptr)šŸ‘ˆ? I don't bother checking that pointers are not NULL when using them, nor do I bother to free() in code coach. Both of those would be excellent habits. Are you allowing space for the '\0' in your strings/pointers? I had missed learning sscanf, thanks for showing me the easy way to convert strings!!! I had also neglected to learn %02d, seems I'm moving too quickly for the information to stick in my old brain....
29th Jan 2022, 8:48 AM
HungryTradie
HungryTradie - avatar
+ 2
Hello HungryTradie Thanks for helping with my code! I know the condition that ā€œtest case 5ā€ demands now, but Iā€™m not sure yet how I will go about fulfilling it. In a nutshell, the program needs to be able to take a time value with a trailing zero as input (08:00 AM). My scanf statement was mishandling this criterion. Iā€™ll post my updated code when Iā€™ve cracked it! Any ideas welcome! I like your modulo implementation to remove error checking and clean things up; Iā€™ll try it out. Thanks!
29th Jan 2022, 8:39 AM
Sean
+ 1
G'day Sean you can link your code bits, but you can't link to the code challenge attempts. Many people copy from their attempt & save it into a new code bit.
29th Jan 2022, 3:34 AM
HungryTradie
HungryTradie - avatar
+ 1
Thanks HungryTradie I fixed it in the original post.
29th Jan 2022, 3:40 AM
Sean
+ 1
G'day Sean Did you get this working? I looked at a few other people's codes, and have then implemented a working version in C. I used your idea of checking for 'P' and then *12. After that I used modulo to bring 24 back to 0. No error checking, no wrong input detection, nothing fancy. Good luck mate! for those reading this in prosperity: https://code.sololearn.com/c6K4C2vphSRj/?ref=app
29th Jan 2022, 8:29 AM
HungryTradie
HungryTradie - avatar
+ 1
Youā€™re right; it worked! Wow, thanks so much for all your help! I reposted my code since I was able to pare it down along the way: https://code.sololearn.com/c8dHxqq34NU8/?ref=app
29th Jan 2022, 4:54 PM
Sean