[英]GCC |warning: implicit declaration of function '_stricmp' [-Wimplicit-function-declaration]|
[英]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;
##
##}
字符串空間不足。 還增加了掃描限制
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.