




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include #include #include #define BUF_SIZE 4096typedef struct char *key;int num;char *trans;word_t;void sys_err(const char *msg)perror(msg);exit(1);int word_num(const char *filename)FILE *fp;char bufBUF_SIZE;int total = 0;fp = fopen(filename, r);if(fp = NULL)sys_err(open filen);while(fgets(buf, BUF_SIZE, fp) != NULL)if(buf0 = #)total+;fclose(fp);return total;int nword(const char *filename)FILE *fp;char bufBUF_SIZE;int total = 0;fp = fopen(filename, r+);if(fp = NULL)sys_err(open filen);while(fgets(buf, BUF_SIZE, fp) != NULL)if(buf0 = #)total+;fclose(fp);return total;word_t *init_word(int total, const char *filename)/将文本写入缓存中FILE *fp;char bufBUF_SIZE;int i, j;fp = fopen(filename, r);if(fp = NULL)sys_err(open filen);word_t *dict = (word_t *)malloc(total * sizeof(word_t);while(fgets(buf, BUF_SIZE, fp) != NULL)if(buf0 = #)dict-key = malloc(strlen(buf) - 1);bufstrlen(buf) - 1 = 0;strcpy(dict-key, buf+1);elsedict-num = 0;bufstrlen(buf)-1 = ;for(i = 0; i num+;dict-trans = (char *)malloc(sizeof(char *) * dict-num);int pos = -1;char *p = buf + 6;for(j = 6; bufj != 0; j+)if(bufj = )pos+;bufj = 0;dict-transpos = (char *)malloc(sizeof(char) * (strlen(p) + 1);strcpy(dict-transpos, p);p = buf+ j + 1;dict+;fclose(fp);dict = dict-total;return dict;int partition(word_t *dict,int start, int end)/排序int i, last = start;word_t tmp, *pivot;pivot = dict+start;for(i = start+1; i key, pivot-key) start)mid = partition(dict, start, end);quicksort(dict, start, mid-1);quicksort(dict, mid+1, end);word_t *binarysearch(word_t *dict,char *str, int total)/二分查找int mid, start = 0, end = total - 1;while(start key, str) key, str) 0)end = mid - 1;elsereturn dict+mid;return NULL;void print(const word_t *dict)/打印单词和解释int i;printf(-n);printf(word : n, dict-key);for(i = 0;i num; i+)printf(Trans %d: %sn, i+1,dict-transi);printf(-n);void insert_new_word(const char *filename)/添加新词到自己的词库FILE *fp;char bufBUF_SIZE;fp = fopen(filename, a+);if(fp = NULL)sys_err(open filen);printf(Please enter the word like this: (#hello)n);fgets(buf, BUF_SIZE, stdin);fprintf(fp, %s, buf);printf(Please enter the trans like this: (Trans:vt nihaowei)n);fgets(buf, BUF_SIZE, stdin);fprintf(fp,%s, buf);fclose(fp);void usr_txt(char *str,const char *filename)/用户自己的词库查找int n_word, i;word_t *dict;n_word = nword(filename);dict = init_word(n_word, filename);for(i = 0; i 0)system(clear);count+;if(strcmp(str, #) = 0)break;if(binarysearch(dict, str, end) != NULL)print(binarysearch(dict, str, end);elsechar ch32;printf(Sorry, cant find such word in system-library !nDo you want to go to yourselfs word-library ? ( y or n) );while(1)fgets(ch, 32, stdin);chstrlen(ch)-1 = 0;if(strcmp(ch, y) = 0)printf(Please input the filename of your word-library : )while(1)fgets(filename, 32, stdin);filenamestrlen(filename)-1 = 0;FILE *fp;if(fp = fopen(filename, r) != NULL)break;elseprintf(Cant find such text which you inputed.nPlease input the filename again: );usr_txt(str, filename);break;else if(strcmp(ch, n) = 0)break;elseprintf(Undefind command: %snPlease input your choice again :(y or n), ch);else if(strcmp(choice, 2) = 0)system(clear);printf(*n);printf(* Byebye! *n);printf(*n);return 1;elseprintf(Undefind command: %sn.Please i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030中国教育培训产业发展趋势分析与未来投资战略咨询研究报告
- 2025-2030中国带状疱疹疫苗市场教育策略与接种率预测研究报告
- 论初高中学生在学习中的自主学习和自我管理
- 酒店餐厅垃圾分类规定
- 2025年中学教师资格考试《综合素质》教育教学能力提升模拟试卷(含答案)
- 2025年健身教练职业技能考核试卷:健身教练运动训练安全与风险管理试题
- 基于GIS技术的金沙江溪洛渡水电站库区水库塌岸预测与风险评价研究
- 物流行业仓储管理操作流程规范手册
- 初中地理教学改革与教学总结
- 基于fMRI技术探究问题解决中学习效应的神经机制
- 2025至2030中国智能卡行业市场深度调研报告
- 民族地区小学英语情境教学实践探索
- TSG Z7005-2015 特种设备无损检测机构 核准规则
- 儿童超重或肥胖的规范化诊断与评估(2024)解读课件
- GB/T 45333-2025类金刚石薄膜球盘法测试类金刚石薄膜的摩擦磨损性能
- 农产品检测技术实习心得范文
- 种植业可研报告范文
- 《复活(节选)》统编版高中语文选择性必修上册
- 《水墨风格动画》课件
- 销售合同协议书模板集
- 南通市启秀初中2024-2025八年级上学期第一次月考物理试卷及答案
评论
0/150
提交评论