电子辞典课程设计方案

上传人:m**** 文档编号:67325953 上传时间:2022-03-30 格式:DOC 页数:49 大小:1.35MB
收藏 版权申诉 举报 下载
电子辞典课程设计方案_第1页
第1页 / 共49页
电子辞典课程设计方案_第2页
第2页 / 共49页
电子辞典课程设计方案_第3页
第3页 / 共49页
资源描述:

《电子辞典课程设计方案》由会员分享,可在线阅读,更多相关《电子辞典课程设计方案(49页珍藏版)》请在装配图网上搜索。

1、课程名称Linux下的标准C设计题目英汉电子辞典项目组长邢美慧组 员丁宝陈飞郭宗良欧阳晨阳指导教师王建立2014目录一、设计时间 0二、设计目的0三、需求分析 03.1单词查询03.2建立索引,并使用索引进行单词查询 03.3用户添加新词0四、系统分析 14.1 功能分析14.1.1 系统功能分析14.1.2 文本查找功能分析 1建立索引功能分析 1索引查找功能分析 14.1.5 添加新词功能分析 24.2概要设计24.2.1 系统功能结构图24.2.2 文本查找功能图3建立索引功能图44.2.4 索引查找功能图54.2.5 添加新词功能图64.3 各模块细化分析 74.3.1 内存存储结构-

2、哈希表的实现74.3.2 二进制索引文件构造图 84.3.3 文本查询细化分析 94.3.4 建立索引文件细化分析 124.3.5 索引查询细化分析174.3.6 添加新词细化分析 20五、系统设计 215.1硬件环境215.2选择语言215.3功能关系225.4框架设计235.5 详细设计235.5.1 抽象数据类型235.5.2 函数接口声明24六、编码286.1模块1代码286.2模块2代码336.3模块3代码376.4模块4代码396.5主函数代码41七、测试427.1单元测试427.1.1 模块1测试427.1.2 模块2测试447.1.3 模块3测试447.1.4 模块4测试477

3、.2集成测试48八、使用说明书49九、维护49一、设计时间2014年8月18日-2014年8月25日二、设计目的通过本次课程设计,熟悉C语言的程序设计与技巧,进一步提高编写程序,分析程序及上机操作,调试程序的能力,提高动手操作能力及分析问题和解决问题的能力三、需求分析3.1单词查询给定文本文件“ dict.txt ”该文件用于存储词库。词库为“英-汉” “汉-英”双语词典,每个单词和其解释的格式固定,如下所示:#单词Trans:解释1解释2解释n每个新单词由“ #”开头,解释之间使用“ ”隔开。一个词可能有多个解释,解释均存储在一行里,行首固定以“ Trans:开头。下面是一个典型的例子:#a

4、byss inianTrans:a.阿比西尼亚的 n.阿比西尼亚人;依索比亚人该词有两个解释,一个是“ a.阿比西尼亚的”;另一个是“ n.阿比西尼亚人;依索比亚人”。 要求编写程序将词库文件读取到内存中,接受用户输入的单词, 在字典中查找单词, 并且将解释输出到屏幕上。用户可以反复输入,直到用户输入“exit ”字典程序退出。程序执行格式如下所示:./app - text-text表示使用文本词库进行单词查找。3.2建立索引,并使用索引进行单词查询要求建立二进制索引,索引格式如下图所示。将文本文件“dict.txt 文件转换为上图所示索引文件“dict.dat”,使用索引文件实现单词查找。程

5、序执行格式如下:./app - index-index表示使用文本词库 dict.txt建立二进制索引词库dict.dat./app - bin-bin表示使用二进制索引词库进行单词查找。3.3用户添加新词用户添加的新词存放在指定文件中。如果待查单词在词库中找不到,则使用用户提供的词库。用户的词库使用文本形式保存,便于用户修改。程序执行格式图1-1所示。./app词库选择选项-f用户词库文件名词库选项为-test1,或者-test2,表示使用文本词库或者二进制索引词库。-f为固定参数,用来指定用户词库文件名。四、系统分析4.1功能分析系统功能分析该项目包含4个主要功能:使用文本文件进行单词查询

6、;使用文本文件生成二进制索引文件; 使用二进制索引文件进行单词查询;用户添加新词;当用户输入./app -text执行功能1 ;当用户输入./app -index执行功能2 ;当用户输入./app -bin执行功能3;当用户输入./app -insert执行功能4;文本查找功能分析当用户从终端输入./app -text后进入该功能模块,系统会提示用户输入要查询的 英文单词,当用户键入待查单词后,程序会先从dict.txt文件中查询该单词,若查到,即在终端显示解释;若未查到,再到自定义文本 my_dict.txt中查询,若查到,即在终端显示解释;若未查到,则在终端提示“此单词未找到”。用户可以反

7、复查询,直到键入Exit结束整个程序。建立索引功能分析当用户从终端输入./app -in dex后进入该功能模块,系统会生成一个新的二进制文件dict.dat,若原已存在,将会被覆盖,程序将文本文件dict.txt 中的内容写进该二进制文件,并且生成一个目录写进该二进制文件,在建立完成后将会提示“建立成功”索引查找功能分析当用户从终端输入./app -bin后进入该功能模块,系统会提示用户输入要查询的英文单词,当用户键入待查单词后,程序会从二进制索引文件dict.dat中查询该单词,若查到,即在终端显示解释;若未查到,则在终端提示“此单词未找到”。用户可以反复查询,直到键入 Exit结束该程序

8、。添加新词功能分析当用户从终端输入./app -insert后进入该功能模块,系统会提示用户要插入的英文单词,当用户键入待插单词后,程序会先在标准文本和自定义文本两个文件中查找该单词,若查到,则提示“该单词已存在,不能添加”;若未查到,则提示用户输入待插单词的所有解释,将单词及解释写进自定义文本my_dict.txt 中4.2概要设计系统功能结构图模块设计文本查询单词app -text建立索引文件app -index索引文件查询单词/app -biri添加新词 /app -insert图-系统功能422文本查找功能图图 modulel.ddd423建立索引功能图厂开始load memory t

9、ext dddbuild dat index ddd图 module2.ddd424索引查找功能图图 module3.ddd425添加新词功能图图 module4.ddd4.3各模块细化分析内存存储结构-哈希表的实现分析:1.将同一个解释的长度和内容组成一个结点;2. 将同一个单词的所有解释存储在一条链表上;3. 将一个单词的长度、内容、解释个数及解释链表的头指针组成一个结点;4. 将所有单词首字母相同的单词结点存储在一条链表上;5. 声明一个结构体数组,数组元素分别存放 26个英文字母和26条单词链表 的头指针abcd1ef碗度需内容next指针匚二孵融蹿内容i单词巖单词内容sm務脂针=”

10、NULILNULL图哈希表存储结构好处:1.只加载英文部分,加载速度很快2.锁定在特定链表中查询,查找速度很快二进制索引文件构造图单词1檢度(415)1单词1内容 (若干宇节)单词1解樺 柚(4宇节)解释1长度(455)解释1内容 (若干宁节)解程2氏宸(4字节)解釋2內容 偌1Ff5)解轻门怏JS(4宇节)解怪ri肉容 借干宇节单词2长度(4宁节单词2内容 (若干字节)and so on 略目录目录开始的 索引(long单词个数 (long)433文本查询细化分析4.3.3.1 力口载内存图 load_memory_text.ddd图 clear_space.ddd4.333 在哈希表中查询

11、单词4.334在自定义文本中查询单词图 search_word_text.ddd图 search_word_mytext.ddd建立索引文件细化分析4.341建立二进制索引文件图 build_dat_i ndex.ddd4.3.4.2将文本内容写入二进制索引文件图 write_c onten t_dat_i ndex.ddd4.343 将目录写进二进制索引文件开蛤-卅打幵索引文件丁开成功获取Mat文件指针兰i前也墨存到某个int变鈕中初始化目录结点的个数word numO关闭文件返回0返回t和WEd num:结束口指向目录谁轰下个结点图 write list dat index.ddd4.34

12、4将目录开始的索引写进二进制索引文件结束-)图 write_listkey_dat_ in dex.ddd4.345将单词个数写进二进制索引文件抽打幵索引文件N将里i司个數写进dat文件中;/文件打幵黄败关网文件i|5!siizeofitrans length)个字节 赋绪该结点.第i个解澤的长度读?&izeaftran&曲耐)个字节赃涪该箔占第并解释的內容jtrans nsrng)个宇壬图 search_word_with_ in dex_b in. ddd436添加新词细化分析4.3.6.1将单词及解释写进自定义文本中N/I添加成咖/藩加失畋! /1f关闭文件( 结束 J图 write_w

13、ord_mytext_i nsert.ddd五、系统设计5.1硬件环境支持Linux下的gcc编译环境5.2选择语言c语言5.3功能关系startImodulelload_me moryjextcreate_trans_niodei n s ert_trsns _n extc re ate_word_n ode_t exti n s ert_word_n ode_texlclear_spaceseardi_word_textse 3 rch_ward_mytext load_memory_text S9arch_wrd_textmodulesIloadmemorytextclear_space

14、write content dat indexwnte_li st_dat_ind ex write_l i stkey_d3t_i ndex write_w0(dn u m_dat_indexin s ert_i ndex_node_i nde xIbuild dat index moduleloadmemorybinIinsertnelec_ncfcleS68fCh_indeK_binse a nch_word_with_i ndex_binmodule4load_mennofy_text dear_pace search_word_Lexi sea rch_wa rd_mtext wri

15、t e_word_myt ext_i nsert5.4框架设计main.c提示用法mo-dukl.cmadule2xnnaduleS.cnnadule4.c5.5详细设计抽象数据类型typedef struct trans tran s_t;typedef struct word word_t; typedef struct first first_t; typedef struct array array_t;typedef struct in dex in dex_t; typedef struct in dexdata in dex_data;/*1.存放解释的结构体*/struct t

16、ransint tran s_le ngth;char trans_n ameSIZE; trans_t *n ext;typedef trans_t *tra ns_p;1*2.存放单词的结构体*/struct wordint word_le ngth;char word _n ameSIZE;int trans_num; trans_p head; word_t *n ext;typedef word_t *word_p;/*3.存放哈希数组元素的结构体*/struct firstchar ch; word_p n ext;;typedef first_t *first_p;1*4.存放指

17、针哈希数组的结构体*/struct arrayfirst_p hash26;typedef array_t *array_p;/*5.存放目录的结构体*/struct in dexchar word _n ameSIZE; long positi on; in dex_t *n ext;typedef in dex_t *in dex_p;/*6.存放目录数据域的结构体*/struct in dexdatachar word _n ameSIZE; long positi on;5.5.2 函数接口声明5.5.2.1 模块 1函数原型:void module1(void) 函数参数:void函

18、数返回值类型:void函数功能:使用文本词库进行单词查询函数原型:array_p load_memory_text(char *,array_p) 函数参数:char * ,array_p 函数返回值类型:array_p函数功能:文本词库加载到内存中,采用哈希表结构函数原型: word_p search_word_text(array_p,char *) 函数参数:array_p , char * 函数返回值类型:word p函数功能:哈希表中查找单词函数原型: word_p search_word_mytext(char *,char *) 函数参数:char * , char *函数返回值

19、类型:word_p函数功能:自定义文本词库中查找单词函数原型:trans_p create_tra ns_no de_text(char *)函数参数:char *函数返回值类型:trans_p函数功能:生成解释结点函数原型:trans_p in sert_tra ns_no de_text(tra ns_p,tra ns_p) 函数参数:trans_p , trans_p函数返回值类型:trans_p函数功能:解释结点插到解释链表尾部函数原型: word_p create_word_ no de_text(char *,tra ns_p) 函数参数:char * ,trans_p函数返回值类

20、型:word_p函数功能:生成单词结点函数原型:word_p in sert_word_ no de_text(word_p,word_p) 函数参数:word_p,word_p函数返回值类型:word_p函数功能:单词结点插到单词链表尾部函数原型:int get_tra ns_nu m(tra ns_p)函数参数:trans_p函数返回值类型:int函数功能:获取某个单词的解释个数函数原型:void prin t_hash(array_p)函数参数:array_p函数返回值类型:void函数功能:遍历哈希表函数原型:void prin t_word(word_p)函数参数:word_p函数返

21、回值类型:void函数功能:遍历单词链表函数原型:void clear_space(char *)函数参数:char *函数返回值类型:void函数功能:清除字符串后的空格5.522 模块2函数原型:void module2(void)函数参数:void函数返回值类型:void函数功能:建立二进制索引文件函数原型:void build_dat_i ndex(array_p,char *)函数参数:array_p,char *函数返回值类型:void函数功能:生成二进制索引文件函数原型:in dex_p write_c onten t_dat_i ndex(array_p,char *)函数参数

22、:array_p,char *函数返回值类型:in dex_p函数功能:将哈希表中的内容写进二进制文件,并保存每个单词所对的索引,生成目录函数原型:long write_list_dat_i ndex(i ndex_p,char *,lo ng *)函数参数:in dex_p,char *,lo ng *函数返回值类型:long函数功能:将目录写进 dat文件,并保存目录开始的索引和目录中单词的个数函数原型:void write_listkey_dat_i ndex(lo ng)函数参数:long函数返回值类型:void函数功能:将目录开始的索引写进 dat文件函数原型:void write_

23、word nu m_dat_ in dex(l ong)函数参数:long函数返回值类型:void函数功能:将目录中单词的个数写进dat文件函数原型:in dex p in sert in dex node in dex(i ndex p,i ndex p)函数参数:in dex_p,i ndex_p函数返回值类型:in dex_p函数功能:目录结点插到目录链表头部5.523 模块3函数原型:void module3(void)函数参数:void函数返回值类型:void函数功能:使用二进制索引文件进行单词查询函数原型:in dex_p load_memory_b in( char *,i nd

24、ex_p)函数参数:char *,i ndex_p函数返回值类型:in dex_p函数功能:将二进制索引文件中的目录加载到内存中,采用链表结构函数原型:long search_ in dex_b in (i ndex_p,char *)函数参数:in dex_p,char *函数返回值类型:long函数功能:目录链表中查找单词对应的索引函数原型: word_p search_word_with_ in dex_b in( char *,l ong)函数参数:char *,lo ng函数返回值类型:word_p函数功能:dat中查找某个索引相对应的单词内容及解释5.524 模块4函数原型:voi

25、d module4(void) 函数参数:void函数返回值类型:void函数功能:添加新词到自定义文本中函数原型:void write_word_mytext_i nsert(char *,char *)函数参数:char *,char *函数返回值类型:void函数功能:写入新词及其解释到自定义文本六、编码6.1模块1代码#i nclude #i nclude #in elude #in elude /*/*模块1:使用文本词库进行单词查询*/*/*1.使用文本词库进行单词查询*/void module1(void)int i;char str30;array_p poin t=(arra

26、y_p)malloc(sizeof(array_t);for(i=0;ihashi=(first_p)malloc(sizeof(first_t);poi nt-hashi-ch=a+i;poi nt-hashi- next=NULL;poin t=load_memory_text(dict.txt,po in t);while(1)prin tf(Please in put word:);gets(str);clear_space(str);if(strcmp(str,Exit)=O)return ;elseword_p result=search_word_text(po in t,str

27、);if(result=NULL)word_p result2=search_word_mytext(my_dict.txt,str); if(result2=NULL)prin tf(Sorry,word n ot foun d!n);elsetrans_p p=result2-head;while(p!=NULL)puts(p-tra ns_n ame); p=p-n ext;elsetrans_p p=result-head;while(p!=NULL)puts(p-tra ns_n ame);p=p-n ext;1*2.文本词库加载到内存中,采用哈希表结构*/array_p load_

28、memory_text(char *file name,array_p point)int i,j,m,c,flag;FILE *fp;word_p n ew_word;trans_p n ew_tra ns,tra ns_head;if(fp=fope n(file name,r)=NULL)prin tf(Sorry,file ope n failed!n);return point;while(1)char bufferSIZE=0,strSIZE=0;flag=0;if(c=fgetc(fp)=EOF)fclose(fp);return poi nt;if(c=#)tran s_hea

29、d=NULL;i=0,j=0;while(c=fgetc(fp)!=n) bufferi+=c;while(c=fgetc(fp)!=n)if(c!=)strj+=c;elsen ew_tra ns=create_tra ns_no de_text(str);tran s_head=in sert_tra ns_no de_text(tra ns_head, new_tra ns); j=0;for(m=0;mSIZE;m+) strm=0;n ew_tra ns=create_tra ns_no de_text(str);tran s_head=in sert_tra ns_no de_te

30、xt(tra ns_head ,n ew_tra ns); n ew_word=create_word_ no de_text(buffer,tra ns_head);for(i=0;ihashi-ch)flag=1;poi nt-hashi- next=i nsert_word_ino de_text(poi nt-hashi- next, new_word); break; if(!flag)fclose(fp);return poi nt;/*3.哈希表中查找单词*/word_p search_word_text(array_p poin t,char *str)int i;for(i=

31、0;ihashi-ch)word_p p=po in t-hashi-n ext;while(p!=NULL)if(strcmp(p-word_ name,str)=0) retur n p;elsep=p-n ext;return NULL;return NULL;/*4.自定义文本词库中查找单词*/word_p search_word_mytext(char *file name,char *str)int i;array_p poin t=(array_p)malloc(sizeof(array_t);for(i=0;ihashi=(first_p)malloc(sizeof(first

32、_t);poi nt-hashi-ch=a+i;poi nt-hashi- next=NULL;poin t=load_memory_text(file name,po in t); word_p result=search_word_text(po in t,str); return result;/*5.生成解释结点*/trans_p create_tra ns_no de_text(char *str)tran s_p n ew=(tra ns_p)malloc(sizeof(tra ns_t); strcpy (n ew-tra ns_n ame,str);n ew-tra nsen

33、gth=strle n( str);n ew-n ext=NULL;return n ew;/*6.解释结点插到解释链表尾部*/trans_p in sert_tra ns_no de_text(tra ns_p head,tra ns_p newnode) if(head=NULL)newno de-n ext=NULL; head=newno de;elsetrans_p p=head;while(p-n ext!=NULL)p=p-n ext;newno de-n ext=NULL; p-n ext=newno de;retur n head;/*7.生成单词结点*/word_p cre

34、ate_word_ no de_text(char *str1,tra ns_p head)word_p newno de=(word_p)malloc(sizeof(word_t); strcpy (newno de-word_ name,str1);newno de-worden gth=strle n(newno de-word_ name); newno de-head=head;newno de-n ext=NULL;newno de-tra ns_num=get_tra ns_nu m( newno de-head); retur n newno de;1*8.单词结点插到单词链表

35、尾部*/word_p in sert_word _no de_text(word_p head,word_p newnode) if(head=NULL)newno de-n ext=NULL;head=newno de;elseword_p p=head;while(p-n ext!=NULL)p=p-n ext;newno de-n ext=NULL;p-n ext=newno de;retur n head;/*9.获取某个单词的解释个数*/int get_tra ns_nu m(tra ns_p head)int len gth=0;trans_p p=head;while(p!=NU

36、LL)len gth+;p=p-n ext;return len gth;/*10.遍历哈希表*/void prin t_hash(array_p point)int i;word_p p;for(i=0;ihashi-n ext;while(p!=NULL)puts(p-word_ name);trans_p t=p-head;while(t!=NULL)prin tf(%s;,t-tra ns_n ame);t=t- n ext;putchar(n);p=p-n ext;return ;/*11.遍历单词链表*/void prin t_word(word_p head)word_p p=h

37、ead;while(p!=NULL) puts(p-word_ name); trans_p t=p-head; while(t!=NULL)prin tf(%s;,t-tra ns_n ame); t=t- n ext; putchar(n); p=p-n ext;return;/*12.清除字符串后的空格*/void clear_space(char *str)if(strstrlen(str)-1=) strstrle n(str)-1=O: clear_space(str);return ;6.2模块2代码#i nclude #i nclude #in clude #in clude

38、/*/*模块2:建立二进制索引文件*/*/*1.建立二进制索引文件*/void module2(void)int i;array_p poin t=(array_p)malloc(sizeof(array_t); for(i=0;ihashi=(first_p)malloc(sizeof(first_t);poi nt_hashi_ch=a+i;poi nt-hashi- next=NULL;poin t=load_memory_text(dict.txt,po in t);build_dat_i ndex(poi nt,dict.dat); return ;/*2.生成二进制索引文件*/vo

39、id build_dat_i ndex(array_p poin t,char *file name)FILE *fp;long word_ nu m,start_ in dex;fp=fope n(file name,w);fclose(fp);in dex_p head=write_c on te nt_dat_i ndex(poi nt,file name); start_i ndex=write _l ist_dat_i ndex(head,file name,&word_ nu m); writeistkey_dat_i ndex(start_i ndex);write_word n

40、um _dat_i ndex(word _nu m);printf(%ld words has been built finished!n,word_inum); return ;,生成目录*/*3.将哈希表中的内容写进二进制文件,并保存每个单词所对的索引 in dex_p write_c onten t_dat_i ndex(array_p poin t,char *file name) int i;FILE *fp;word_p p;tran s_p t;in dex_p n ew,head;head=NULL;if(fp=fope n( dict.dat,ab)=NULL)prin tf

41、(Sorry,file ope n failed! n);return NULL;elsefor(i=0;ihashi-n ext;while(p!=NULL)n ew=(i ndex_p)malloc(sizeof( in dex_t);strcpy (n ew-word_ name,p-word_ name);n ew-positi on=ftell(fp);n ew-n ext=NULL;head=in sert_ in dex_ node_in dex(head, new);fwrite(&p-word_le ngth,sizeof(p-word_le ngth),1,fp); fwr

42、ite(p-word_ name,sizeof(p-word_ name),1,fp);fwrite(&p-tra ns_nu m,sizeof(p-tra ns_nu m),1,fp); t=p-head;while(t!=NULL)fwrite(&t-tra ns_len gth,sizeof(t-tra ns_len gth),1,fp); fwrite(t-tra ns_n ame,sizeof(t-tra ns_n ame),1,fp); t=t- n ext;p=p-n ext;fclose(fp);retur n head;/*4.将目录写进dat文件,并保存目录开始的索引和目录

43、中单词的个数*/long write_list_dat_ in dex(i ndex_p head,char *file name,l ong *word_ num)FILE *fp;int t;in dex_p p=head;in dex_data n ew;*word _num=0;if(fp=fope n( ”dict.dat”,”ab”)=NULL)prin tf(Sorry,file ope n failed!n);return 0;elset=ftell(fp);while(p!=NULL)strcpy (n ew.word_ name,p-word_ name);n ew.pos

44、iti on=p-positi on;fwrite(&n ew,sizeof(i ndex_data),1,fp);(*word _nu m)+;p=p-n ext;fclose(fp);return t;/*5.将目录开始的索引写进dat文件*/void write_listkey_dat_ in dex(lo ng start_ in dex)FILE *fp;if(fp=fope n( ”dict.dat”,”ab”)=NULL)prin tf(Sorry,file ope n failed!n);return ;elsefwrite(&start_ in dex,sizeof( Ion

45、 g),1,fp);fclose(fp);/*6.将目录中单词的个数写进dat文件*/void write_word nu m_dat_ in dex(l ong word _num)FILE *fp;if(fp=fope n(dict.dat,ab)=NULL)prin tf(Sorry,file ope n failed!n);return ;elsefwrite(&word_ nu m,sizeof( Ion g),1,fp);fclose(fp);return;/*7.目录结点插到目录链表头部*/in dex_p in sert_ in dex_ node_in dex(i ndex_

46、p head,i ndex_p newnode) newno de-n ext=head;head=newno de;retur n head;6.3模块3代码#i nclude #i nclude #in elude #in elude /*/*模块3:使用二进制索引文件进行单词查询*/*/*1.使用二进制索引文件进行单词查询*/void module3(void)char str30;long in dex;in dex_p head=NULL;word_p result;tran s_p t; head=load_memory_b in (dict.dat,head);while(1)p

47、rin tf(Please in put word:);gets(str);clear_space(str);if(strcmp(str,Exit)=O)return ;elsein dex=searchn dex_bi n(head,str);if(i ndex=-1)prin tf(Sorry,word not foun d!n);elseresult=search_word_with_i ndex_b in (dict.dat,i ndex); t=result-head;while(t!=NULL)puts(t-tra ns_n ame);t=t- n ext;/*2.将二进制索引文件

48、中的目录加载到内存中,采用链表结构*/in dex_p load_memory_b in( char *file name,i ndex_p head)FILE *fp;int i;long startndex,word_ num;in dex_p n ew;in dex_data n ew_data;fp=fope n(file name,rb);if(fp=NULL)prin tf(Sorry,file ope n failed!n); return NULL;fseek(fp,-2*sizeof(lo ng),SEEK_END);fread(&start_ in dex,sizeof(

49、Ion g),1,fp); fread(&word_ nu m,sizeof( Ion g),1,fp); fseek(fp,start_i ndex,SEEK_SET);for(i=0;iword_ name ,n ew_data.word_ name);n ew-positi on=n ew_data.positi on;head=in sert_i ndex_ node_in dex(head ,n ew);fclose(fp);retur n head;/*3.目录链表中查找单词对应的索引*/long search_ in dex_b in (i ndex_p head,char *s

50、tr)in dex_p p=head;while(p!=NULL)if(strcmp(p-word_ name,str)=0) retur n p-positi on; p=p-n ext;return -1;/*4.dat中查找某个索引相对应的单词内容及解释*/word_p search_word_with_ in dex_b in( char *file name,lo ng positi on) FILE *fp;int i;word_p n ew;trans_p trans_no de,tra ns_head=NULL;fp=fope n(file name,rb);if(fp=NUL

51、L)prin tf(Sorry,file ope n failed!n);return NULL;fseek(fp,positio n,SEEK_SET);n ew=(word_p)malloc(sizeof(word_t);fread(&n ew-word _len gth,sizeof( new-word _len gth),1,fp);fread( new-word_ name,sizeof( new-word_ name),1,fp);fread(&n ew-tra ns_nu m,sizeof( new-tra ns_nu m),1,fp);for(i=0;itra ns_nu m;i+)trans_no de=(tra ns_p)malloc(sizeof(tra ns_t);fread( &trans_no de-tra ns_le ngth,sizeof(tra ns_no de-tra ns_len gth),1,fp); fread(tra ns_no de-tra ns_n ame,sizeof(tra ns_no de-tra ns_n ame),1,fp); tran s_head=in sert_tra ns_no de_text(tra ns_head,tra ns_no de);

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!