欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

浙大版《C语言程序设计(第3版)》题目集 习题11-2 查找星期 (15分)

程序员文章站 2022-06-08 17:03:01
...

浙大版《C语言程序设计(第3版)》题目集 习题11-2 查找星期 (15分)

#include <stdio.h>
#include <string.h>
#define MAXS 80
int getindex(char *s);
int main()
{
    int n;
    char s[MAXS];
    scanf("%s", s);
    n = getindex(s);
    if (n == -1)
        printf("wrong input!\n");
    else
        printf("%d\n", n);
    return 0;
}
int getindex(char *s)
{
    int week;
    char *day[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    //这里使用  day[7][10] 也行 并且*day[7]在dev中有 警告??
    for (week = 0; week <= 6; week++)
    {
        if (strcmp(s, day[week]) == 0)
            break;
    }
    if (week == 7)
        week = -1;
    return week;
}