- 205
- 0
- 约3.28千字
- 约 7页
- 2018-03-26 发布于河南
- 举报
c背单词软件(可导入词库)
实习报告
一、需求分析
题目:背单词程序
要求::程序使用词汇表文件,其中每个词条由单词和解释两部分组成,编程完成:用户输入一个单词,程序将给出单词的词性和中文意思。
建立一个词汇表测试用词汇表名为新东方红宝书.txt,用c语言文件操作打开该文件,并将文件读入命名为dictionary[DICTSIZE]的数组内。读入数据存储于dictionary[DICTSIZE]所分配的地址空间内,以8字节表示一个信息。
二、程序设计
数据类型定义:
Int a,b; 作为是否继续判断的依据
char *buf;要输入的单词
int index;哈西表查找到的字符的地址值
void DoWord;把单词赋给数组
int MakeDict;打开单词文件
int SearchWordByHash;哈西查找
int GetValueByWord;算出哈西函数值
三,设计思路
从文件中读入一个字符,在文件中进行哈西查找,运用哈西查找可以提高效率。
程序流程图
四、使用说明
按照程序提示说明输入一个英文单词,按回车键,程序将在文件中进行查找,找到单词是将显示出单词的词性及中文意思。
注:因为单词文件中单词数量有限因此,当查找不到这个单词时程序将提示用户单词无法找到。
当查找结束后,程序将询问用户是否继续查找,若继续请按1退出请按2。
五、测试结果
六、其他
源代码注释:
#include conio.h
#include string.h
#include stdio.h
#define BUFFER_SIZE 100
#define DICTSIZE 8000
#define WORDLEN 100
void DoWord(char* word,int num);
int MakeDict(char *filename,int num);
int SearchWordByHash(char *word,int num);
int GetValueByWord(char *word,int num);
struct Dword
{
char data[WORDLEN];
char mean[WORDLEN];
}dictionary[DICTSIZE];
int DictNum, Ret;
FILE *fout;
void main()
{
printf(欢迎光临学生字典,请输入您想查找的单词\n);
printf(我将把您想查找的英文单词的词性和中文意思告诉您\n);
int a = 1;
while (a != 0){ //输入0退出,其它任意键继续
char *buf; //定义一个指针指向要查找的单词
char str[10];
int index;
buf = str;
scanf(%s, buf); //输入要查找的单词
printf(%s ,buf);
MakeDict(新东方红宝书.txt,DictNum);
index=SearchWordByHash(buf,DictNum);
if( -1 == index ) {
printf(单词表中没有这个单词\n);
}
else {
printf(这个单词的意思是:%s ,dictionary[index].mean);
}
printf(继续查找请按1,退出请按0\n);
int b;
scanf(%d, b);
a = b; //确定a的值
}
}
void DoWord(char* word,int num) //把单词赋给数组
{
int i,f=0,k1=0,k2=0,worlen,tn;
char ctemp[WORDLEN];
worlen=strlen(word);
for(i=0;iworlen;i++) // ctemp = word
{
if(word[i]!= )
ctemp[i]=word[i];
else
break;
}
ctemp[i]=\0;
tn=GetValueByWord(ctemp,num);
if(dictionary[tn].data[0]!=0)
for(tn=0;tnnum;tn++)
if(dictionary[tn].data[0]==0)
break;
f=0;
for(i=0;iworlen;i++)
{
if(word[i]!= f==0)
{
dictionary[tn].data[k1]=word[i];
原创力文档

文档评论(0)