作者在 2013-01-03 03:27:33 发布以下内容
/*输入英文月份单词,输出对应月的数字形式*/
#include <stdio.h>
#include <string.h>
int search(char list[][20],char name[],int m)
{
int i;
for(i=0;i<m;i++)
if(strcmp(list[i],name)==0)//用name跟月份数组逐个对比
break;
return i;
}
int main()
{
char month_list[12][20]={"January","February","March","April","May","June","July","August","Setemper","October","November","December"};
char month[20];//定义一个数组存储你输入的月份单词(无论你输入正确与否)
int n;
gets(month);
n=search(month_list,month,12);
if(n<12)
printf("%s表示%d月\n",month,n+1);
else
printf("查无此单词\n");
}