+ 1

What is the problem with this military time code coach problem of mine?

#include<stdio.h> #include<string.h> char str[100]; char spc[100]; int main() { int i, j,k,x,n,m,len; fgets(str, 100, stdin); for(i=0;i<strlen(str);i++) { if(str[i]==58) { for(j=i;j<strlen(str);j++) { str[j]=str[j+1]; } } } for(k=0;k<4;k++) { spc[k]=str[k]; } //printf("%s", spc); x = atoi(spc); //printf("%d",x); m = x/100; n = x%100; len = strlen(str); if(str[len-3] == 80) { m = m+12; if(n < 10) { printf("%d:0%d",m,n); } else { printf("%d:%d",m,n); } } else { if(m < 10 && n<10 ) printf("0%d:0%d",m,n); else if(m < 10 && n >= 10) printf("0%d:%d",m,n); else if(m >= 10 && n < 10) printf("%d:0%d",m,n); else if(m >= 10 && n >= 10) printf("%d:%d",m,n); } }

3rd May 2022, 10:16 AM
NERD 2 NERD
4 Respuestas
+ 7
Put your code in a script on sololearn playground instead of copying everything into the description – it is hardly readable and we can't test it. Go to Code section, click +, select the programming language, insert your code, save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
3rd May 2022, 5:30 PM
Lisa
Lisa - avatar
+ 2
Just tested: Input: 01:30PM Output: 13:30 Doesn't already work as intended?
4th May 2022, 9:58 AM
OrHy3
OrHy3 - avatar
+ 1
Also use clearer variable names and some comments. Helps a lot, including yourself, in the near future.
4th May 2022, 2:50 AM
Emerson Prado
Emerson Prado - avatar
+ 1
And please, insted of ASCII values use the characters (e.g. 'P' instead of 80)
4th May 2022, 9:59 AM
OrHy3
OrHy3 - avatar