電子辭典-課程設計_第1頁
電子辭典-課程設計_第2頁
電子辭典-課程設計_第3頁
電子辭典-課程設計_第4頁
電子辭典-課程設計_第5頁
已閱讀5頁,還剩48頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、 課程名稱 Linux下的標準C 設計題目 英漢電子辭典 項目組長 邢美慧 組 員 丁寶 陳飛 郭宗良 歐陽晨陽 指導教師 王建立 2014 年 8 月目錄一、設計時間1二、設計目的1三、需求分析13.1 單詞查詢13.2 建立索引,并使用索引進行單詞查詢13.3 用戶添加新詞1四、系統(tǒng)分析24.1 功能分析24.1.1 系統(tǒng)功能分析24.1.2 文本查找功能分析24.1.3 建立索引功能分析24.1.4 索引查找功能分析24.1.5 添加新詞功能分析34.2 概要設計34.2.1 系統(tǒng)功能結(jié)構(gòu)圖34.2.2 文本查找功能圖44.2.3 建立索引功能圖54.2.4 索引查找功能圖64.2.5

2、添加新詞功能圖74.3 各模塊細化分析84.3.1 內(nèi)存存儲結(jié)構(gòu) - 哈希表的實現(xiàn)84.3.2 二進制索引文件構(gòu)造圖94.3.3 文本查詢細化分析94.3.4 建立索引文件細化分析124.3.5 索引查詢細化分析164.3.6 添加新詞細化分析19五、系統(tǒng)設計205.1 硬件環(huán)境215.2 選擇語言215.3 功能關(guān)系215.4 框架設計225.5 詳細設計235.5.1 抽象數(shù)據(jù)類型235.5.2 函數(shù)接口聲明23六、 編碼276.1 模塊1代碼286.2 模塊2代碼286.3 模塊3代碼366.4 模塊4代碼396.5 主函數(shù)代碼41七、 測試417.1 單元測試427.1.1 模塊1測試

3、427.1.2 模塊2測試437.1.3 模塊3測試447.1.4 模塊4測試467.2 集成測試47八、使用說明書48九、維護49一、設計時間2014年8月18日-2014年8月25日二、設計目的通過本次課程設計,熟悉C語言的程序設計與技巧,進一步提高編寫程序,分析程序及上機操作,調(diào)試程序的能力,提高動手操作能力及分析問題和解決問題的能力三、需求分析3.1 單詞查詢給定文本文件“dict.txt”,該文件用于存儲詞庫。詞庫為“英-漢”,“漢-英”雙語詞典,每個單詞和其解釋的格式固定,如下所示:#單詞Trans:解釋1解釋2解釋n每個新單詞由“#”開頭,解釋之間使用“”隔開。一個詞可能有多個解

4、釋,解釋均存儲在一行里,行首固定以“Trans:”開頭。下面是一個典型的例子:#abyssinianTrans:a. 阿比西尼亞的n. 阿比西尼亞人;依索比亞人該詞有兩個解釋,一個是“a. 阿比西尼亞的”;另一個是“n. 阿比西尼亞人;依索比亞人”。要求編寫程序?qū)⒃~庫文件讀取到內(nèi)存中,接受用戶輸入的單詞,在字典中查找單詞,并且將解釋輸出到屏幕上。用戶可以反復輸入,直到用戶輸入“exit”字典程序退出。程序執(zhí)行格式如下所示:./app text-text表示使用文本詞庫進行單詞查找。3.2 建立索引,并使用索引進行單詞查詢要求建立二進制索引,索引格式如下圖所示。將文本文件“dict.txt”文件

5、轉(zhuǎn)換為上圖所示索引文件“dict.dat”,使用索引文件實現(xiàn)單詞查找。程序執(zhí)行格式如下:./app index-index表示使用文本詞庫dict.txt建立二進制索引詞庫dict.dat./app bin-bin表示使用二進制索引詞庫進行單詞查找。3.3 用戶添加新詞用戶添加的新詞存放在指定文件中。如果待查單詞在詞庫中找不到,則使用用戶提供的詞庫。用戶的詞庫使用文本形式保存,便于用戶修改。程序執(zhí)行格式圖1-1所示。./app 詞庫選擇選項 -f 用戶詞庫文件名詞庫選項為-test1,或者-test2,表示使用文本詞庫或者二進制索引詞庫。-f為固定參數(shù),用來指定用戶詞庫文件名。四、系統(tǒng)分析4.

6、1 功能分析4.1.1 系統(tǒng)功能分析該項目包含4個主要功能:使用文本文件進行單詞查詢;使用文本文件生成二進制索引文件;使用二進制索引文件進行單詞查詢;用戶添加新詞; 當用戶輸入./app -text 執(zhí)行功能1; 當用戶輸入./app -index 執(zhí)行功能2; 當用戶輸入./app -bin 執(zhí)行功能3; 當用戶輸入./app -insert 執(zhí)行功能4;4.1.2 文本查找功能分析當用戶從終端輸入./app -text后進入該功能模塊,系統(tǒng)會提示用戶輸入要查詢的英文單詞,當用戶鍵入待查單詞后,程序會先從dict.txt文件中查詢該單詞,若查到,即在終端顯示解釋;若未查到,再到自定義文本my

7、_dict.txt中查詢,若查到,即在終端顯示解釋;若未查到,則在終端提示“此單詞未找到”。用戶可以反復查詢,直到鍵入Exit結(jié)束整個程序。4.1.3 建立索引功能分析當用戶從終端輸入./app -index后進入該功能模塊,系統(tǒng)會生成一個新的二進制文件dict.dat,若原已存在,將會被覆蓋,程序?qū)⑽谋疚募ict.txt中的內(nèi)容寫進該二進制文件,并且生成一個目錄寫進該二進制文件,在建立完成后將會提示“建立成功”4.1.4 索引查找功能分析當用戶從終端輸入./app -bin后進入該功能模塊,系統(tǒng)會提示用戶輸入要查詢的英文單詞,當用戶鍵入待查單詞后,程序會從二進制索引文件dict.dat中查

8、詢該單詞,若查到,即在終端顯示解釋;若未查到,則在終端提示“此單詞未找到”。用戶可以反復查詢,直到鍵入Exit結(jié)束該程序。4.1.5 添加新詞功能分析當用戶從終端輸入./app -insert后進入該功能模塊,系統(tǒng)會提示用戶要插入的英文單詞,當用戶鍵入待插單詞后,程序會先在標準文本和自定義文本兩個文件中查找該單詞,若查到,則提示“該單詞已存在,不能添加”;若未查到,則提示用戶輸入待插單詞的所有解釋,將單詞及解釋寫進自定義文本my_dict.txt中4.2 概要設計4.2.1 系統(tǒng)功能結(jié)構(gòu)圖圖-系統(tǒng)功能4.2.2 文本查找功能圖圖 module1.ddd4.2.3 建立索引功能圖圖 module

9、2.ddd4.2.4 索引查找功能圖圖 module3.ddd4.2.5 添加新詞功能圖圖 module4.ddd4.3 各模塊細化分析4.3.1 內(nèi)存存儲結(jié)構(gòu) - 哈希表的實現(xiàn)分析:1.將同一個解釋的長度和內(nèi)容組成一個結(jié)點; 2.將同一個單詞的所有解釋存儲在一條鏈表上; 3.將一個單詞的長度、內(nèi)容、解釋個數(shù)及解釋鏈表的頭指針組成一個結(jié)點; 4.將所有單詞首字母相同的單詞結(jié)點存儲在一條鏈表上; 5.聲明一個結(jié)構(gòu)體數(shù)組,數(shù)組元素分別存放26個英文字母和26條單詞鏈表 的頭指針圖 哈希表存儲結(jié)構(gòu) 好處:1.只加載英文部分,加載速度很快 2.鎖定在特定鏈表中查詢,查找速度很快4.3.2 二進制索引文

10、件構(gòu)造圖4.3.3 文本查詢細化分析4.3.3.1 加載內(nèi)存圖 load_memory_text.ddd4.3.3.2 清除字符串后的空格圖 clear_space.ddd4.3.3.3 在哈希表中查詢單詞圖search_word_text.ddd4.3.3.4 在自定義文本中查詢單詞圖 search_word_mytext.ddd4.3.4 建立索引文件細化分析4.3.4.1 建立二進制索引文件圖 build_dat_index.ddd4.3.4.2 將文本內(nèi)容寫入二進制索引文件圖 write_content_dat_index.ddd4.3.4.3 將目錄寫進二進制索引文件圖 write_

11、list_dat_index.ddd4.3.4.4 將目錄開始的索引寫進二進制索引文件 圖 write_listkey_dat_index.ddd4.3.4.5 將單詞個數(shù)寫進二進制索引文件 圖 write_wordnum_dat_index.ddd4.3.5 索引查詢細化分析4.3.5.1 加載內(nèi)存 圖 Load_memory_bin.ddd4.3.5.2 在目錄中查詢單詞圖 search_index_bin.ddd4.3.5.3 通過索引在正文中查詢單詞圖 search_word_with_index_bin.ddd4.3.6 添加新詞細化分析4.3.6.1 將單詞及解釋寫進自定義文本中圖

12、 write_word_mytext_insert.ddd五、系統(tǒng)設計5.1 硬件環(huán)境支持Linux下的gcc編譯環(huán)境5.2 選擇語言C語言5.3 功能關(guān)系5.4 框架設計5.5 詳細設計5.5.1 抽象數(shù)據(jù)類型typedef struct trans trans_t;typedef struct word word_t;typedef struct first first_t;typedef struct array array_t;typedef struct index index_t;typedef struct indexdata index_data;/*1.存放解釋的結(jié)構(gòu)體*/s

13、truct transint trans_length;char trans_nameSIZE;trans_t *next;typedef trans_t *trans_p;/*2.存放單詞的結(jié)構(gòu)體*/struct wordint word_length;char word_nameSIZE;int trans_num;trans_p head;word_t *next;typedef word_t *word_p;/*3.存放哈希數(shù)組元素的結(jié)構(gòu)體*/struct firstchar ch;word_p next;typedef first_t *first_p;/*4.存放指針哈希數(shù)組的結(jié)構(gòu)

14、體*/struct arrayfirst_p hash26;typedef array_t *array_p; /*5.存放目錄的結(jié)構(gòu)體*/struct indexchar word_nameSIZE;long position;index_t *next;typedef index_t *index_p;/*6.存放目錄數(shù)據(jù)域的結(jié)構(gòu)體*/struct indexdatachar word_nameSIZE;long position;5.5.2 函數(shù)接口聲明5.5.2.1 模塊1函數(shù)原型:void module1(void)函數(shù)參數(shù):void函數(shù)返回值類型:void函數(shù)功能:使用文本詞庫進行

15、單詞查詢函數(shù)原型:array_p load_memory_text(char *,array_p)函數(shù)參數(shù):char *,array_p函數(shù)返回值類型:array_p函數(shù)功能:文本詞庫加載到內(nèi)存中,采用哈希表結(jié)構(gòu)函數(shù)原型:word_p search_word_text(array_p,char *)函數(shù)參數(shù):array_p,char *函數(shù)返回值類型:word_p函數(shù)功能:哈希表中查找單詞函數(shù)原型:word_p search_word_mytext(char *,char *)函數(shù)參數(shù):char *,char *函數(shù)返回值類型:word_p函數(shù)功能:自定義文本詞庫中查找單詞函數(shù)原型:trans

16、_p create_trans_node_text(char *)函數(shù)參數(shù):char *函數(shù)返回值類型:trans_p函數(shù)功能:生成解釋結(jié)點函數(shù)原型:trans_p insert_trans_node_text(trans_p,trans_p)函數(shù)參數(shù):trans_p,trans_p函數(shù)返回值類型:trans_p函數(shù)功能:解釋結(jié)點插到解釋鏈表尾部函數(shù)原型:word_p create_word_node_text(char *,trans_p)函數(shù)參數(shù):char *,trans_p函數(shù)返回值類型:word_p函數(shù)功能:生成單詞結(jié)點函數(shù)原型:word_p insert_word_node_text

17、(word_p,word_p)函數(shù)參數(shù):word_p,word_p函數(shù)返回值類型:word_p函數(shù)功能:單詞結(jié)點插到單詞鏈表尾部函數(shù)原型:int get_trans_num(trans_p)函數(shù)參數(shù):trans_p函數(shù)返回值類型:int函數(shù)功能:獲取某個單詞的解釋個數(shù)函數(shù)原型:void print_hash(array_p)函數(shù)參數(shù):array_p函數(shù)返回值類型:void函數(shù)功能:遍歷哈希表函數(shù)原型:void print_word(word_p)函數(shù)參數(shù):word_p函數(shù)返回值類型:void函數(shù)功能:遍歷單詞鏈表函數(shù)原型:void clear_space(char *)函數(shù)參數(shù):char *函

18、數(shù)返回值類型:void函數(shù)功能:清除字符串后的空格5.5.2.2 模塊2函數(shù)原型:void module2(void)函數(shù)參數(shù):void函數(shù)返回值類型:void函數(shù)功能:建立二進制索引文件函數(shù)原型:void build_dat_index(array_p,char *)函數(shù)參數(shù):array_p,char *函數(shù)返回值類型:void函數(shù)功能:生成二進制索引文件函數(shù)原型:index_p write_content_dat_index(array_p,char *)函數(shù)參數(shù):array_p,char *函數(shù)返回值類型:index_p函數(shù)功能:將哈希表中的內(nèi)容寫進二進制文件,并保存每個單詞所對的索引,

19、生成目錄函數(shù)原型:long write_list_dat_index(index_p,char *,long *)函數(shù)參數(shù):index_p,char *,long *函數(shù)返回值類型:long函數(shù)功能:將目錄寫進dat文件,并保存目錄開始的索引和目錄中單詞的個數(shù)函數(shù)原型:void write_listkey_dat_index(long)函數(shù)參數(shù):long函數(shù)返回值類型:void函數(shù)功能:將目錄開始的索引寫進dat文件函數(shù)原型:void write_wordnum_dat_index(long)函數(shù)參數(shù):long函數(shù)返回值類型:void函數(shù)功能:將目錄中單詞的個數(shù)寫進dat文件函數(shù)原型:inde

20、x_p insert_index_node_index(index_p,index_p)函數(shù)參數(shù):index_p,index_p函數(shù)返回值類型:index_p函數(shù)功能:目錄結(jié)點插到目錄鏈表頭部5.5.2.3 模塊3函數(shù)原型:void module3(void)函數(shù)參數(shù):void函數(shù)返回值類型:void函數(shù)功能:使用二進制索引文件進行單詞查詢函數(shù)原型:index_p load_memory_bin(char *,index_p)函數(shù)參數(shù):char *,index_p函數(shù)返回值類型:index_p函數(shù)功能:將二進制索引文件中的目錄加載到內(nèi)存中,采用鏈表結(jié)構(gòu)函數(shù)原型:long search_inde

21、x_bin(index_p,char *) 函數(shù)參數(shù):index_p,char *函數(shù)返回值類型:long函數(shù)功能:目錄鏈表中查找單詞對應的索引函數(shù)原型:word_p search_word_with_index_bin(char *,long) 函數(shù)參數(shù):char *,long函數(shù)返回值類型:word_p函數(shù)功能:dat中查找某個索引相對應的單詞內(nèi)容及解釋5.5.2.4 模塊4函數(shù)原型: void module4(void) 函數(shù)參數(shù):void函數(shù)返回值類型:void函數(shù)功能:添加新詞到自定義文本中函數(shù)原型:void write_word_mytext_insert(char *,char

22、*)函數(shù)參數(shù):char *,char *函數(shù)返回值類型:void函數(shù)功能:寫入新詞及其解釋到自定義文本6、 編碼6.1 模塊1代碼#include <stdio.h>#include <stdlib.h>#include <string.h>#include <my_word.h>/*-*/* 模塊1: 使用文本詞庫進行單詞查詢 */ /*-*/*1.使用文本詞庫進行單詞查詢*/ void module1(void)int i;char str30;array_p point=(array_p)malloc(sizeof(array_t);for

23、(i=0;i<26;i+)point->hashi=(first_p)malloc(sizeof(first_t);point->hashi->ch='a'+i;point->hashi->next=NULL;point=load_memory_text("dict.txt",point);while(1)printf("Please input word:");gets(str);clear_space(str);if(strcmp(str,"Exit")=0)return ;el

24、seword_p result=search_word_text(point,str);if(result=NULL)word_p result2=search_word_mytext("my_dict.txt",str);if(result2=NULL)printf("Sorry,word not found!n");elsetrans_p p=result2->head;while(p!=NULL)puts(p->trans_name);p=p->next;elsetrans_p p=result->head;while(p!

25、=NULL)puts(p->trans_name);p=p->next;/*2.文本詞庫加載到內(nèi)存中,采用哈希表結(jié)構(gòu)*/array_p load_memory_text(char *filename,array_p point)int i,j,m,c,flag;FILE *fp;word_p new_word;trans_p new_trans,trans_head;if(fp=fopen(filename,"r")=NULL)printf("Sorry,file open failed!n");return point;while(1)ch

26、ar bufferSIZE='0',strSIZE='0'flag=0;if(c=fgetc(fp)=EOF)fclose(fp);return point;if(c='#')trans_head=NULL;i=0,j=0;while(c=fgetc(fp)!='n')bufferi+=c;while(c=fgetc(fp)!='n')if(c!='')strj+=c;elsenew_trans=create_trans_node_text(str);trans_head=insert_trans_

27、node_text(trans_head,new_trans);j=0;for(m=0;m<SIZE;m+)strm='0'new_trans=create_trans_node_text(str);trans_head=insert_trans_node_text(trans_head,new_trans);new_word=create_word_node_text(buffer,trans_head);for(i=0;i<26;i+)if(buffer0=point->hashi->ch)flag=1;point->hashi->nex

28、t=insert_word_node_text(point->hashi->next,new_word);break;if(!flag)fclose(fp);return point;/*3.哈希表中查找單詞*/word_p search_word_text(array_p point,char *str)int i;for(i=0;i<26;i+)if(str0=point->hashi->ch)word_p p=point->hashi->next;while(p!=NULL)if(strcmp(p->word_name,str)=0)ret

29、urn p;elsep=p->next;return NULL;return NULL;/*4.自定義文本詞庫中查找單詞*/word_p search_word_mytext(char *filename,char *str)int i;array_p point=(array_p)malloc(sizeof(array_t);for(i=0;i<26;i+)point->hashi=(first_p)malloc(sizeof(first_t);point->hashi->ch='a'+i;point->hashi->next=NUL

30、L;point=load_memory_text(filename,point);word_p result=search_word_text(point,str);return result;/*5.生成解釋結(jié)點*/trans_p create_trans_node_text(char *str)trans_p new=(trans_p)malloc(sizeof(trans_t);strcpy(new->trans_name,str);new->trans_length=strlen(str);new->next=NULL;return new;/*6.解釋結(jié)點插到解釋鏈

31、表尾部*/trans_p insert_trans_node_text(trans_p head,trans_p newnode)if(head=NULL)newnode->next=NULL;head=newnode;elsetrans_p p=head;while(p->next!=NULL)p=p->next;newnode->next=NULL;p->next=newnode;return head;/*7.生成單詞結(jié)點*/word_p create_word_node_text(char *str1,trans_p head)word_p newnode

32、=(word_p)malloc(sizeof(word_t);strcpy(newnode->word_name,str1);newnode->word_length=strlen(newnode->word_name);newnode->head=head;newnode->next=NULL;newnode->trans_num=get_trans_num(newnode->head);return newnode;/*8.單詞結(jié)點插到單詞鏈表尾部*/word_p insert_word_node_text(word_p head,word_p n

33、ewnode)if(head=NULL)newnode->next=NULL;head=newnode;elseword_p p=head;while(p->next!=NULL)p=p->next;newnode->next=NULL;p->next=newnode;return head;/*9.獲取某個單詞的解釋個數(shù)*/int get_trans_num(trans_p head)int length=0;trans_p p=head;while(p!=NULL)length+;p=p->next;return length;/*10.遍歷哈希表*/v

34、oid print_hash(array_p point)int i;word_p p;for(i=0;i<26;i+)p=point->hashi->next;while(p!=NULL)puts(p->word_name);trans_p t=p->head;while(t!=NULL)printf("%s;",t->trans_name);t=t->next;putchar('n');p=p->next;return ;/*11.遍歷單詞鏈表*/void print_word(word_p head)wo

35、rd_p p=head;while(p!=NULL)puts(p->word_name);trans_p t=p->head;while(t!=NULL)printf("%s;",t->trans_name);t=t->next;putchar('n');p=p->next;return;/*12.清除字符串后的空格*/void clear_space(char *str)if(strstrlen(str)-1=' ')strstrlen(str)-1='0'clear_space(str);re

36、turn ;6.2 模塊2代碼#include <stdio.h>#include <stdlib.h>#include <string.h>#include <my_word.h>/*-*/* 模塊2: 建立二進制索引文件 */*-*/*1.建立二進制索引文件*/void module2(void)int i;array_p point=(array_p)malloc(sizeof(array_t);for(i=0;i<26;i+)point->hashi=(first_p)malloc(sizeof(first_t);point-

37、>hashi->ch='a'+i;point->hashi->next=NULL;point=load_memory_text("dict.txt",point);build_dat_index(point,"dict.dat");return ;/*2.生成二進制索引文件*/void build_dat_index(array_p point,char *filename)FILE *fp;long word_num,start_index;fp=fopen(filename,"w");fcl

38、ose(fp);index_p head=write_content_dat_index(point,filename);start_index=write_list_dat_index(head,filename,&word_num);write_listkey_dat_index(start_index);write_wordnum_dat_index(word_num);printf("%ld words has been built finished!n",word_num);return ;/*3.將哈希表中的內(nèi)容寫進二進制文件,并保存每個單詞所對的索引,

39、生成目錄*/index_p write_content_dat_index(array_p point,char *filename)int i;FILE *fp;word_p p;trans_p t;index_p new,head;head=NULL;if(fp=fopen("dict.dat","ab")=NULL)printf("Sorry,file open failed!n");return NULL;elsefor(i=0;i<26;i+)p=point->hashi->next;while(p!=NU

40、LL)new=(index_p)malloc(sizeof(index_t);strcpy(new->word_name,p->word_name);new->position=ftell(fp);new->next=NULL;head=insert_index_node_index(head,new);fwrite(&p->word_length,sizeof(p->word_length),1,fp);fwrite(p->word_name,sizeof(p->word_name),1,fp);fwrite(&p->tr

41、ans_num,sizeof(p->trans_num),1,fp);t=p->head;while(t!=NULL)fwrite(&t->trans_length,sizeof(t->trans_length),1,fp);fwrite(t->trans_name,sizeof(t->trans_name),1,fp);t=t->next;p=p->next;fclose(fp);return head;/*4.將目錄寫進dat文件,并保存目錄開始的索引和目錄中單詞的個數(shù)*/long write_list_dat_index(index

42、_p head,char *filename,long *word_num)FILE *fp;int t;index_p p=head;index_data new;*word_num=0;if(fp=fopen("dict.dat","ab")=NULL)printf("Sorry,file open failed!n");return 0;elset=ftell(fp);while(p!=NULL)strcpy(new.word_name,p->word_name);new.position=p->position;f

43、write(&new,sizeof(index_data),1,fp);(*word_num)+;p=p->next;fclose(fp);return t;/*5.將目錄開始的索引寫進dat文件*/void write_listkey_dat_index(long start_index)FILE *fp;if(fp=fopen("dict.dat","ab")=NULL)printf("Sorry,file open failed!n");return ;elsefwrite(&start_index,siz

44、eof(long),1,fp);fclose(fp);/*6.將目錄中單詞的個數(shù)寫進dat文件*/void write_wordnum_dat_index(long word_num)FILE *fp;if(fp=fopen("dict.dat","ab")=NULL)printf("Sorry,file open failed!n");return ;elsefwrite(&word_num,sizeof(long),1,fp);fclose(fp);return;/*7.目錄結(jié)點插到目錄鏈表頭部*/index_p inse

45、rt_index_node_index(index_p head,index_p newnode)newnode->next=head;head=newnode;return head;6.3 模塊3代碼#include <stdio.h>#include <stdlib.h>#include <string.h>#include <my_word.h>/*-*/* 模塊3: 使用二進制索引文件進行單詞查詢 */*-*/*1.使用二進制索引文件進行單詞查詢*/void module3(void) char str30;long index;

46、index_p head=NULL;word_p result;trans_p t;head=load_memory_bin("dict.dat",head);while(1)printf("Please input word:");gets(str);clear_space(str);if(strcmp(str,"Exit")=0)return ;elseindex=search_index_bin(head,str);if(index=-1)printf("Sorry,word not found!n");el

47、seresult=search_word_with_index_bin("dict.dat",index);t=result->head;while(t!=NULL)puts(t->trans_name);t=t->next;/*2.將二進制索引文件中的目錄加載到內(nèi)存中,采用鏈表結(jié)構(gòu)*/index_p load_memory_bin(char *filename,index_p head)FILE *fp;int i;long start_index,word_num;index_p new;index_data new_data;fp=fopen(fil

48、ename,"rb");if(fp=NULL)printf("Sorry,file open failed!n");return NULL;fseek(fp,-2*sizeof(long),SEEK_END); fread(&start_index,sizeof(long),1,fp);fread(&word_num,sizeof(long),1,fp);fseek(fp,start_index,SEEK_SET);for(i=0;i<word_num;i+)new=(index_p)malloc(sizeof(index_t);f

49、read(&new_data,sizeof(index_data),1,fp);strcpy(new->word_name,new_data.word_name);new->position=new_data.position;head=insert_index_node_index(head,new);fclose(fp);return head; /*3.目錄鏈表中查找單詞對應的索引*/long search_index_bin(index_p head,char *str) index_p p=head;while(p!=NULL)if(strcmp(p->word_name,str)=0)return p->position;p=p->next;return -1;/*4.dat中查找某個索引相對應的單詞內(nèi)容及解釋*/word_p search_word_with_index_bin(char *filename,long position) FILE *fp;int i;word_p new;trans_p trans_node,trans_head=NULL;fp=fopen(filename,"rb&qu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論