+ 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
9 Answers
+ 3
Hey Sean .... It's your use of %i. Change them all to %d & it works!
+ 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.
+ 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....
+ 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!
+ 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.
+ 1
Thanks HungryTradie
I fixed it in the original post.
+ 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
+ 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