0
I'm not able to initialize value to "hh", Can anyone help??
/* take input like this "07:05:45AM" keep in mind AM and PM should be "CAPITAL" */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { int hh, mm, ss; char t12[2]; scanf("%d:%d:%d%s", &hh, &mm, &ss, t12); if(strcmp(t12, "PM") == 0) { hh += 12; } else if(strcmp(t12, "AM") == 0) { hh = 0; } printf("%02d:%02d:%02d", hh, mm, ss); return 0; }
4 Antworten
+ 1
If your trying in here SL playground, scanf don't work in in cpp unless you have cin used..
Try in c or make using c++ code..
+ 1
In other compilers, am not sure but
in scanf, it won't output from scanf so remove : from scanf, and give some spaces like
scanf("%d %d %d %s", &hh, &mm, &ss, t12);
0
I'm just asking in general not in reference of sololearn
0
Take the null character into account as well, "AM" and "PM" both require 3 characters, not 2.