#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;
}
strcmp(line,xjf[i].abr == 0)
==>strcmp(line,xjf[i].abr) == 0