#include#define MAX 30
int main()
{
FILE *fp;
int i,flag = 0,t,Y=1,flag1=0;
int n1 = 20432 , n2 = MAX , j ;
char buf1[MAX],buf2[MAX],**array;
array = (char **)malloc(n1*sizeof(char *));
fp = fopen("文件保存路径(如:F:\\Linux_report\\idiom.txt)","r");
if(NULL == fp)
{
printf("File open fail\n");
}
for(i = 0 ; i < n1 ; i++)
{
array[i] = (char *)malloc(n2*sizeof(char));
fscanf(fp,"%s",array[i]);
}
for(i = 0 ; !feof(fp) ; i++)
{
fscanf(fp,"%s",array[i]);
}
while(Y==1)
{
printf("Please input an idiom:\n");
scanf("%s",buf1);
for(i = 0 ; i < 20432 ; i++)
{
if(!(strcmp(buf1,array[i])))
{
flag = 1;
break;
}
}
if(flag==0)
{
printf("Your input is not a idiom\n");
return 0;
}
strcpy(buf2,buf1);
while(1)
{
flag = 0 ;
flag1 = 0 ;
for(i = 0 ; i < 20431 ; i++)
{
if((buf2[6]==array[i][0])&&(buf2[7]==array[i][1])&&(array[i][10]!='*'))
{
flag1 = 1 ;
printf("%s\n",array[i]);
strcpy(buf2,array[i]);
array[i][10] = '*' ;
break;
}
}
if(flag1 == 0)
{
printf("YOU WIN!");
return 0;
}
printf("Please input an idiom:\n");
scanf("%s",buf1);
for(i = 0 ; i < 20432 ; i++)
{
if(!(strcmp(buf1,array[i])))
{
flag = 1;
break;
}
}
if(flag==0)
{
printf("Your input is not an idiom\n");
return 0;
}
if((buf1[0]!=buf2[6])||(buf1[1]!=buf2[7]))
{
printf("You fail!");
return 0 ;
}
else
strcpy(buf2,buf1);
}
}
free(array[i]);
free(array);
return 0;
}