简体   繁体   中英

i get this error "solution.c:9:4: warning: implicit declaration of function 'stricmp' [-Wimplicit-function-declaration] x= stricmp(ap,c);"

 #include<stdio.h>
 #include<stdlib.h>
 #include<string.h>
 #include<time.h>
 int main()
 {
             int hh,mm,ss;
             char ap[2];
             scanf("%d%d%d%s",&hh,&mm,&ss,ap);
             if(stricmp(ap,"AM")!=0)
             {
                   hh+=12;

              }
              printf("%d:%d:%d",hh,mm,ss);
              return 0;
            ## 

This code converts a 12 hour clock format to 24 hour clock format

##}

Insufficient string space. Also add limit to scanning

char ap[3];
scanf("%d%d%d%2s",&hh,&mm,&ss,ap);

stricmp is not standard. Use strcasecmp on linux or _stricmp on windows.

Functionally missing the handling of times like 12 34 56 AM which should change to 0 34 56.

if(stricmp(ap,"AM")==0) {
  if (hh >= 12) hh -= 12;
} else if(stricmp(ap,"PM")==0) {
  hh +-= 12;
}

More usual to print minutes.seconds with leading zeros.

printf("%d:%02d:%02d",hh,mm,ss);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM