簡體   English   中英

我收到此錯誤“solution.c:9:4: 警告:函數‘stricmp’的隱式聲明 [-Wimplicit-function-declaration] x= stricmp(ap,c);”

[英]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;
            ## 

此代碼將 12 小時制時鍾格式轉換為 24 小時制時鍾格式

##}

字符串空間不足。 還增加了掃描限制

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

stricmp不是標准的。 在 linux 上使用strcasecmp或在 Windows 上使用_stricmp

在功能上缺少對時間的處理,例如 12 34 56 AM,它應該更改為 0 34 56。

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

更常見的是打印帶前導零的分鍾。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM