You are viewing a single comment's thread. Return to all comments →
the seconds are not displaying properly. Scanf isnt storing the input into ss.
The variable 'ss' is similar to 'mm' or 'hh'. If others are getting displayed, it should also work well. Please recheck code, there might be any minor mistake. Else, post your submission link (or code) here, someone would be able to help for sure after looking at the code.
try adding 0 before %2d , that is , do %0d in your printf statement.
I think its an issue with the version of C I am using or the compiler. The code executes fine when submitted through Hackerrank. However, on my own machine, it seems that SS is stored as 00 if scanf contains %d%s for the last input. It works fine if you get rid of the string. Strange.
Actually , my code has a small mistake which I corrected and now it has passed all the testcases.
There is no problem with the code. The problem is because of the underlying architecture on which your compiler is running.
I tried it on windows, it gives correct result but gives wrong answer on linux.
See this http://ideone.com/EV58mh
Here 'time' is stored before 'hour'.
Same is happenning in your case and you are not getting correct value for ss.
I feel like this solution is not complete. We can't change how the underlying system works now, so I think it is programmers responsibility to consider all these situations into account and write an effective solution.
A programmer's responsibility is to consider the system for which s/he is coding. https://www.hackerrank.com/environment is all to be concerned about here; and the code handles that pretty well. It will be nightmare to write even small codes if you have to think about all the possible combination of systems.
Anyways this is a place to learn and improve skills. You are free to give new & better ideas. So, why not help each other by showing better alternatives; instead of cribbing & complaining about those who are already doing.
haha, calm down mate! I am neither cribbing nor complaining. Being a discussuion forum, I would like to discuss my views and get feedback. I am trying to learn more than simple programs that anyone can do after a while. Discussions help you in learning something new from someone. And I wasn't rude either! Please make sure to not make such comments, this forum is just for discussing and that's what I too believe in.
All these apart, from what you have said "A programmer's responsibility is to consider the system for which s/he is coding." It seems that you have no or very less practical experience in developing applications for various platforms. I remember days I struggled because of someone else's such coding approach. Nothing is easy in initial phases, and at least for me it is not a nightmare to write a code that works for multiple systems. Moreover, currently and for quite a long while smartphones rule the world in terms of business. This demands you to develop applications for popular platforms, you shouldn't be wasting time in re-writing code for every system you have out there.
It seems you took my comment in wrong sense. Don't take it otherwise, I expected you'll give some suggestions for improvement in code, which you feel, would remove the problem faced by @Andyuriarte. Since, you only said that "solution is incomplete", I felt it would have been better if you gave some suggestions that might correct the problem, instead of just that. That will actually help all of us to learn. Otherwise, I agree to you mate. Cheers !
Actually, there is a problem with the code. The line char t12; in the original post doesn't allocate enough space. The string "PM" requires three bytes: 'P', 'M', and a null (zero) byte to end the string. When the machine writes three bytes into a two-byte space, that final null byte is stomping over memory that doesn't belong to the t12 variable. What happens then is very hard to predict, dependent on the implementation and other factors.
The quick fix would be to correctly declare t12 as char t12;.
Thanks bro ! I have made the suggested correction in the main code.