如何使用strcmp来解决这个问题?
题目:程序让用户选择语言,如果输入的月份与字符串数组的月份相同(如我输入May,则与char Eng_month内的May相同,则返回(i=4)). 0为拼音,1为英文,程序必须使用一个函数,它调用2个参数,分别是字符串数组和字符串。函数返回相等的那个月份的index(如我输入May,则与char Eng_month内的May相同,则返回(i=4),若没在字符串里发现,则返回-1,要使用strcmp.PS:我大约只能写这么多了,求助!,谢谢!
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
int language (char month[12][10],char input_month[10])
{
int n, x, i=0;
char Chi_month[12][10]={"yiyue","eryue","sanyue","siyue","wuyue","liuyue","qiyue","bayue","jiuyue","shiyue",
"shiyiyue","shieryue"};
char Eng_month[12][10]={"January","February","March","April","May","June","July","Augest","September","October","November","December"};
puts("This program will access a month's index by its name,u can search in two languages: Finnish and English");
puts("0-Pingyin");
puts("1-English");
printf(">> ");
scanf("%d",&n);
puts("Enter the month name in the language u selected.");
printf(">> ");
gets(input_month);
switch(n)
{
case 0:
for (i=0;i<10;i++)
{
x = strcmp (input_month, Fin_month[i]);
printf("Your month is month number %d",i+1);
return i;
}
else
{
printf("Error:Your input month name is wrong!");
return -1;
}
break;
case 1:
if ( x = strcmp (input_month, Eng_month[i]))
{
printf("Your month is month number %d",i+1);
return i;
}
else
{
printf("Error:Your input month name is wrong!");
return -1;
}
break;
default:
printf("Illegal selection! Plz only choose 0 or 1.");
}
return 0;
}
int main(void)
{
int n;
char input_month[10], month[12][10];
n = language (month, input_month);
}