int main(void){ FILE *f,*g; char * buf=NULL; //书目录缓存 if((f = fopen("BookInfo.txt","r")) && (g = fopen("BookIdx.txt","w"))){ IdxListType idxlist; InitIdxList(idxlist);//初始化 ElemType BookNo; if(!(buf=(char *)malloc(MaxLineLen*sizeof(char))))exit(OVERFLOW); while(!feof(f)){ GetLine(f,buf); //printf("%s",buf); ExtractKeyWord(BookNo,buf); InsIdxList(idxlist,BookNo,buf); } PutText(g,idxlist); fclose(f); fclose(g); }else{ printf("File open err!\n"); } printf("\nResult End!\n"); system("pause"); return 0; }
void main() { FILE *f; /* 任何时间最多打开一个文件 */ IdxListType idxlist; /* 索引表 */ int BookNo; /* 书号变量 */ int k,l; f=fopen("NoIdx.txt","r"); /* 打开常用词文件 */ if(!f) exit(OVERFLOW); fscanf(f,"%d",&noidx.last); /* 常用词个数 */ for(k=0;k<noidx.last;k++) /* 把常用词文件的内容拷到noidx中 */ { fscanf(f,"%s",buf); l=strlen(buf); noidx.item[k]=(char*)malloc(l*sizeof(char)); strcpy(noidx.item[k],buf); } fclose(f); f=fopen("BookInfo.txt","r"); /* 打开书目文件 */ if(!f) exit(FALSE); InitIdxList(&idxlist); /* 初始化索引表idxlist为空 */ wdlist.last=0; /* 词表长度初值为0 */ while(!feof(f)) { fgets(buf,MaxLineLen,f); l=strlen(buf); if(l<=1) break; ExtractKeyWord(&BookNo); /* 从buf中提取关键词到词表,书号存入BookNo */ InsIdxList(&idxlist,BookNo); } fclose(f); f=fopen("BookIdx.txt","w"); if(!f) exit(INFEASIBLE); PutText(f,idxlist); /* 将生成的索引表idxlist输出到文件f */ fclose(f); }