
正在写一个课程设计,电子词典C语言,苦于没有词库,谁能帮我连一下词典的数据库,
这是没有数据库的程序,用键树实现#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>...
这是没有数据库的程序,用键树实现
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#define WORDNUM 7000
typedef struct Trie
{
int flag;
Trie *child[26];
char *translation;
} root, node;
typedef struct
{
char word[30];
char translation[100];
} INF;
root *init( )
{
root *r= new root;
r->flag= 0;
for( int i= 0; i< 26; ++i )
r-> child[i]= NULL;
return r;
}
void insert( node *parent, char *in, char *trans )
{
if( *in== '\0' || *in==' ')
{
parent-> flag= 1;
parent-> translation= trans;
return;
}
if( !parent-> child[ *in- 'a' ] )
parent-> child[ *in- 'a' ]= init( );
insert( parent-> child[ *in- 'a' ], in+ 1, trans );
}
bool search( node *parent, char *in )
{
if( *in== '\0' || *in==' ')
{
if( parent-> flag== 1 )
{
printf( "%s\n", parent-> translation );
return true;
}
else
return false;
}
if( !parent-> child[ *in- 'a' ] )
return false;
else
search( parent-> child[ *in- 'a' ], in+ 1 );
return true;
}
bool legal( char chr )
{
if( chr>= 'a'&& chr<= 'z' )
return true;
else
return false;
}
void readfile(root *r)
{
INF info[WORDNUM];
FILE *fp=fopen("output2.txt","r");
if(fp==NULL)
{
printf("文件打开失败!\n");
return ;
}
int i=0;
while(i<178)
{
fgets(info[i].translation,50,fp);
fscanf(fp,"%s",info[i].word);
i++;
}
fclose(fp);
int n=i;
for(i=1;i<n;i++)
insert(r,info[i].word,info[i].translation);
printf("数据初始化成功!\n");
}
void MainMenu( root *r ){
/*主菜单*/
int select;
char word[30];
printf("\n\t\t\t\t* * * * * * * * * * *\n");
printf("\t\t\t\t* 主菜单 *\n");
printf("\t\t\t\t* 1. 添加单词及意义*\n");
printf("\t\t\t\t* 2. 修改单词意义 *\n");
printf("\t\t\t\t* 3. 显示单词意义 *\n");
printf("\t\t\t\t* * * * * * * * * * *\n");
while(1)
{
scanf( "%d", &select );
switch(select)
{
case 1:
printf("\n 1. 添加单词及意义\n");
printf( "请输入你要录入的单词" );
readfile(r);
break;
case 3:
printf("\n 3. 显示单词意义\n");
printf( "请输入你所要查的单词:" );
scanf( "%s", word );
if( ( up= update( r, word ) )== 0 )
printf( "没有" );
else
search( r, word );
break;
default:
printf("输入错误!请重新输入!\n");
break;
}
system("pause");
}
printf("\n\t");
}
int main()
{
root *r= init( );
MainMenu( r );
return 0;
} 展开
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#define WORDNUM 7000
typedef struct Trie
{
int flag;
Trie *child[26];
char *translation;
} root, node;
typedef struct
{
char word[30];
char translation[100];
} INF;
root *init( )
{
root *r= new root;
r->flag= 0;
for( int i= 0; i< 26; ++i )
r-> child[i]= NULL;
return r;
}
void insert( node *parent, char *in, char *trans )
{
if( *in== '\0' || *in==' ')
{
parent-> flag= 1;
parent-> translation= trans;
return;
}
if( !parent-> child[ *in- 'a' ] )
parent-> child[ *in- 'a' ]= init( );
insert( parent-> child[ *in- 'a' ], in+ 1, trans );
}
bool search( node *parent, char *in )
{
if( *in== '\0' || *in==' ')
{
if( parent-> flag== 1 )
{
printf( "%s\n", parent-> translation );
return true;
}
else
return false;
}
if( !parent-> child[ *in- 'a' ] )
return false;
else
search( parent-> child[ *in- 'a' ], in+ 1 );
return true;
}
bool legal( char chr )
{
if( chr>= 'a'&& chr<= 'z' )
return true;
else
return false;
}
void readfile(root *r)
{
INF info[WORDNUM];
FILE *fp=fopen("output2.txt","r");
if(fp==NULL)
{
printf("文件打开失败!\n");
return ;
}
int i=0;
while(i<178)
{
fgets(info[i].translation,50,fp);
fscanf(fp,"%s",info[i].word);
i++;
}
fclose(fp);
int n=i;
for(i=1;i<n;i++)
insert(r,info[i].word,info[i].translation);
printf("数据初始化成功!\n");
}
void MainMenu( root *r ){
/*主菜单*/
int select;
char word[30];
printf("\n\t\t\t\t* * * * * * * * * * *\n");
printf("\t\t\t\t* 主菜单 *\n");
printf("\t\t\t\t* 1. 添加单词及意义*\n");
printf("\t\t\t\t* 2. 修改单词意义 *\n");
printf("\t\t\t\t* 3. 显示单词意义 *\n");
printf("\t\t\t\t* * * * * * * * * * *\n");
while(1)
{
scanf( "%d", &select );
switch(select)
{
case 1:
printf("\n 1. 添加单词及意义\n");
printf( "请输入你要录入的单词" );
readfile(r);
break;
case 3:
printf("\n 3. 显示单词意义\n");
printf( "请输入你所要查的单词:" );
scanf( "%s", word );
if( ( up= update( r, word ) )== 0 )
printf( "没有" );
else
search( r, word );
break;
default:
printf("输入错误!请重新输入!\n");
break;
}
system("pause");
}
printf("\n\t");
}
int main()
{
root *r= init( );
MainMenu( r );
return 0;
} 展开
若以下回答无法解决问题,邀请你更新回答
展开全部
我有词库,不过你的分给的有点少了吧?
更多追问追答
追问
能读进去吗?不过我分有限啊,如果能被我的程序使用的话我就把剩下的分都给你
追答
是这样的,你这个程序我做啦,可以查,是基于我的词库基础上做的,在你的程序中好像不一样,除非你修改你的程序,你也知道,词库都是有规律的,所以你得根据规律来写程序,我的词库打盖有200000多的单词,我给你抄前面的一部分,你看看,你愿意改程序不
#a
Trans:art. 一;字母A
#a.m.
Trans:n. 上午
#a/c
Trans:n. 往来帐户@往来:come - and - go; contact; intercourse@n. 往来帐户
#aardvark
Trans:n. 土猪
#aardwolf
Trans:n. 土狼
#aasvogel
Trans:n. 秃鹰之一种
我的词库是这种类型的,用#开头的是词条,用TRANS开头的是翻译,如果有多条翻译,则之间用字符@隔开
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询