C Primer Plus(第六版)14.18 编程练习 第1题

#include
#include

struct month
{
    char name [10] ;
    char abbrev[4] ;
    int days;
    int monumb;
};

struct month months[12] = 
{
    { "January", "jan", 31,1},
    { "February", "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 count_days(struct month months[]);

int main(void)
{
    int count=0;
    
    puts("Enter a month :");
    count = count_days(months);
    printf("days = %d\n", count);

    return 0;
}

int count_days(struct month months[])
{
    char mont[12];
    int i,count=0;
    scanf("%s",mont);
    for (i = 0; i < 12; i++)
    {    
        count += months[i].days;
            if (strcmp(months[i].name, mont) == 0)
                return count;
    }
    return 0;
}

你可能感兴趣的:(C,Primer,Plus(第六版),c语言,开发语言)