C/C++ code#include
#include
#include
#define SIZE 256
FILE *fp1;
FILE *fp2;
struct hwnt
{
char num[SIZE];
char word[SIZE];
char gern[SIZE];
char def[SIZE];
}hw;
struct mark
{
int layer;
char event[SIZE];
}mk[812];
void Creatmk(char temp[SIZE])//构建标记;
{
char str[SIZE];
int k=1;
while(k!=812)
{
int j=0,count=0,m=0,n=0;
for (j=1;temp[j-1]!='{';j++);
while (temp[j]!='}')
{
str[n]=temp[j];
n++;
j++;
}
str[n]='\0';
strcpy(mk[k-1].event,str);
fgets(temp,SIZE,fp2);
while (temp[m]!='{')//计算空格数,以确定层次关系;
{
if (temp[m]==' ')
count++;
m++;
}
mk[k].layer=count;
k++;
}
}
void main()
{
char *deal_def(char *p,char temp[SIZE]);
char *deal_word(char *p,char temp[SIZE]);
void *deal_gern(char *p);
void Creatmk(char temp[SIZE]);
int i,j=0,flag=0;
char str1[SIZE],str2[SIZE],file1[50],file2[50],temp1[SIZE],temp2[SIZE];
printf("Please input file1 name:\n");
scanf("%s",file1);
printf("Please input file2 name:\n");
scanf("%s",file2);
printf("Please input your parameters:\n");
scanf("%s",str1);
if((fp1=fopen(file1,"rb"))==NULL)
{
printf("cannot open file1\n");
exit(0);
}
if((fp2=fopen(file2,"rb"))==NULL)
{
printf("cannot open file2\n");
exit(0);
}
mk[0].layer=1;
fgets(str2,SIZE,fp2);
Creatmk(str2);
for(i=0;i<162520;i++)
{
fgets(hw.num,SIZE,fp1);
fgets(hw.word,SIZE,fp1);
fgets(hw.gern,SIZE,fp1);
for(j=0;j<4;j++)
fgets(temp1,SIZE,fp1);
fgets(hw.def,SIZE,fp1);
fgets(temp1,SIZE,fp1);
deal_gern(hw.gern);
if(strcmp(hw.gern,str1)==0)
{
printf("%-20s %-20s",deal_word(hw.word,temp2),deal_def(hw.def,temp2));
for(j=0;strcmp(deal_def(hw.def,temp2),mk[j].event)!=0;j++);
flag=mk[j].layer;
while (j>=0)
{
if (mk[j].layer
{
flag=mk[j].layer;
printf("%-20s ",mk[j].event);
}
j--;
}
printf("\n");
}
}
fclose(fp1);
fclose(fp2);
system("pause");
}
char *deal_def(char *p,char temp[SIZE])//处理字符串;
{
int i,n=0;
for (i=1;p[i-1]!='{';i++);
while (p[i]!=':'&&p[i]!='}')
{
temp[n]=p[i];
n++;
i++;
}
temp[n]='\0';
return(temp);
}
void *deal_gern(char *p)//处理字符串,去除回车;
{
int j;
for (j=0;p[j]!=32;j++);
p[j]='\0';
return(p);
}
char *deal_word(char *p,char temp[SIZE])//处理字符串,去除不想要的成分;
{
int i,n=0;
for (i=1;p[i-1]!='=';i++);
while (p[i]!=13)
{
temp[n]=p[i];
n++;
i++;
}
temp[n]='\0';
return(temp);
}