C语言这段代码中这个strcmp哪里有问题,为什么出现warning?谢谢!

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char * s_gets(char * st,int n)

struct month {
    char name[20];
    char abr[4];
    int days;
    int number;
};
struct month xjf[12] = {
    {"January","Jan",31,1},
    {"Febuary","Feb",28,2},
    {"March","Mar",31,3},
    {"April","Apr",30,4},
    {"May","May",31,5},
    {"June","Jun",30,6},
    {"July","Jul",31,7},
    {"August","Aug",31,8},
    {"September","Sep",30,9},
    {"October","Oct",31,10},
    {"November","Nov",30,11},
    {"December","Dec",31,12}
};

int main()
{
    char line[20];
    puts("Please enter month name or abr");
    while (s_gets(line,20) != NULL && line[0] != '\0')
    {
        int total = 0;
        int index = 0;
        for (int i = 0;i < 12;i++)
        {
            if (strcmp(line,xjf[i].name) == 0 || strcmp(line,xjf[i].abr == 0))
            {
                index = xjf[i].number;
                for (int i = 0;i < index;i++)
                total += xjf[i].days;
                printf("There are %d days until %s.\n",total,xjf[index - 1].name);
            }
        }
        if (index == 0)
        puts("Please enter the correct name or abr:");
    }
}


char * s_gets(char * st,int n)
{
    char * ret_val;
    char * find;
    ret_val = fgets(st,n,stdin);
    if (ret_val)
    {
        find = strchr(st,'\n');
        if (find)
        *find = '\0';
        else
        while (getchar() != '\n')
        continue;
    }
    return ret_val;
}
阅读 1k
1 个回答

strcmp(line,xjf[i].abr == 0) ==>
strcmp(line,xjf[i].abr) == 0

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进