void FindMessage()
{
int i,j;
FILE *datafp;
if((datafp=fopen("D:\\fujian.txt","rb"))==NULL)
{
printf("cannot open data file!\n");
return;
}
ClearStructArr(a);
ClearGameItemTable();
for(i=0,j=0;i<50;i++)
{
fscanf(datafp,"%d %d",&GameItemTable[i][0],&GameItemTable[i][1]);
for(int k=0;k<GameItemTable[i][1];k++)
{
a[j].Item=GameItemTable[i][0];
if(fscanf(datafp,"%s %s %ld %d",a[j].name,a[j].Department,&a[j].num,&a[j].Position)==EOF)break;
j++;
}
if(feof(datafp))break;
}
fclose(datafp);
int choice;
printf("How to Find? Make a choice!\n");
printf("1.You can find by your SchoolNumber!\n");
printf("2.You can find by GameItem!\n");
printf("3.You can find by GameItem and GamePosition!\n");
printf("else,You Will exit the Finding...");
scanf("%d",&choice);
if(choice==1)
{
long schoolnum;
int FindIt=1;
printf("Please input the SchoolNumber you want to Find:\n");
scanf("%ld",&schoolnum);
for(i=0;i<50;i++)
{
if(a[i].num==schoolnum)
{
printf("You have Successly Find!\n");
printf("%s,%s,%ld,%d,%d\n",a[i].name,a[i].Department,a[i].num,a[i].Item,a[i].Position);
FindIt=0;
}
}
if(FindIt)
{
printf("Sorry! there is not record like that...\n");
}
}
else if(choice==2)
{
int gameitem;
int FindIt=1;
printf("Please input the GameItem you want to Find:\n");
scanf("%d",&gameitem);
for(i=0;i<50;i++)
{
if(a[i].Item==gameitem)
{
printf("%s,%s,%ld,%d,%d\n",a[i].name,a[i].Department,a[i].num,a[i].Item,a[i].Position);
FindIt=0;
}
}
if(FindIt)
{
printf("Sorry! there is not record like that...\n");
}
else
{
printf("You have Successly Find! Above is the record!\n");
}
}
else if(choice==3)
{
int gameitem1;
int gameposition;
int FindIt=1;
printf("Please input the GameItem and the GamePosition you want to Find:input like(a b)\n");
scanf("%d %d",&gameitem1,&gameposition);
for(i=0;i<50;i++)
{
if((a[i].Item==gameitem1)&&(a[i].Position==gameposition))
{
printf("%s,%s,%ld,%d,%d\n",a[i].name,a[i].Department,a[i].num,a[i].Item,a[i].Position);
FindIt=0;
}
}
if(FindIt)
{
printf("Sorry! there is not record like that...\n");
}
else
{
printf("You have Successly Find! Above is the record!\n");
}
}
else
{
getchar();
return;
}
}
把查找函数也改了下,应该能用,你如果用的TC就把在中间定义的都移上去就行了