㈠ 一种简单英文词典排版系统的实现 c语言编程
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "ctype.h"
#define ROWS 256
#define COLS 32
static FILE *fp;
static char a[ROWS][COLS];
char get_option(void);
int b(int count);
void c(char *pt[], int count);
int check(char arr[], int count);
void storage(char *pt[], int count);
int main(void)
{
int i,count;
int start;
char *pt[ROWS];
char ch, len;
char input;
if((fp=fopen("words.txt","a+"))==NULL)
{
fputs("不能打开或建立文件!\n",stderr);
exit(1);
}
fseek(fp,0L,SEEK_END);
start=(int)ftell(fp)/32;
count=start;
rewind(fp);
if(fread(a,32*sizeof(char),start,fp)==0)
{
i=0;
puts("请输入单词(每行一个),在新行输入END结束输入:");
while(i<ROWS&&scanf("%s", a[i])==1)
{
fflush(stdin);
if(strncmp(a[i],"END",3)==0)
{
count+=i;
break;
}
if(check(a[i], i))
continue;
i++;
}
}
puts("您要做些什么?");
puts("a. 显示已有的单词 b. 添加新单词");
puts("c. 对已有的单词进行排序 d. 退出");
while((input=get_option())!='d')
{
if(input=='a')
{
puts("已有的单词:");
for(i=0;i<count;i++)
{
printf(" ");
puts(a[i]);
}
}
if(input=='b')
{
puts("请输入新的单词(每行一个),在新行输入END结束输入: ");
count=b(count);
}
if(input=='c')
{
puts("对单词进行排序:");
c(pt, count);
for(i=0;i<count;i++)
{
printf(" ");
puts(pt[i]);
}
}
puts("还要做些什么?");
}
storage(pt,count);
fclose(fp);
puts("再见!");
return 0;
}
char get_option(void)
{
char ch;
while((ch=getchar())<'a'||ch>'d')
{
while((ch=getchar())!='\n')
;
puts("请输入a,b,c或者d.");
}
fflush(stdin);
return ch;
}
int b(int count)
{
int i;
i=count;
while(i<ROWS&&scanf("%s", a[i])==1)
{
fflush(stdin);
if(check(a[i], i))
continue;
if(strncmp(a[i],"END",3)==0)
{
count=i;
break;
}
i++;
}
return count;
}
void c(char *pt[], int count)
{
int i,j;
char *temp;
for(i=0;i<ROWS;i++)
pt[i]=a[i];
for(i=0;i<count;i++)
for(j=i+1;j<count;j++)
{
if(strcmp(pt[i],pt[j])>0)
{
temp=pt[i];
pt[i]=pt[j];
pt[j]=temp;
}
}
}
int check(char arr[], int count)
{
int i;
int flag=0;
for(i=0;i<strlen(arr);i++)
if(isalpha(arr[i])==0)
{
printf("%s不是一个单词.\n",arr);
flag=1;
break;
}
for(i=0;i<count;i++)
if(strncmp(a[i],a[count],strlen(a[count])+1)==0)
{
puts("重复的单词!");
flag=1;
}
return flag;
}
void storage(char *pt[], int count)
{
int i,j;
char ptr[ROWS][COLS];
c(pt, count);
for(i=0;i<count;i++)
for(j=0;pt[i][j]!='\0';j++)
ptr[i][j]=pt[i][j];
fp=fopen("words.txt","w+");
rewind(fp);
fwrite(ptr,32*sizeof(char),count,fp);
}
㈡ 运用c语言编写一个英汉字典~ 谢谢啦~先
原型:
int WINAPI icePub_dictionaryCodeTransfer2(char *strDictionaryFilename,char *strSrc,char *strCode,char *strFenge)
输入:strDictionaryFilename 字典文件名
strSrc 待处理单词
strFenge 字典里单词和code之间的分隔符字符串
输出:strCode strSrc对应信息
返回码:
原型:
int WINAPI icePub_dictionaryAddRecord(char *strDictionaryFilename,char *strSrc,char *strCode,char *strFenge)
输入:strDictionaryFilename 字典文件名
strSrc 待添加单词(如果存在则替换)
strCode strSrc对应信息
strFenge 字典里单词和code之间的分隔符字符串
输出:
返回码:
原型:
int WINAPI icePub_dictionaryDelRecord(char *strDictionaryFilename,char *strSrc,char *strFenge)
输入:strDictionaryFilename 字典文件名
strSrc 待删除单词
strFenge 字典里单词和code之间的分隔符字符串
输出:
返回码:
网络一个《icepubdll揭秘》有详细说明
㈢ c语言--编程,电子英汉词典的设计
/*基本的库函数*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define szWORD 32
#define szSTRN 224
#define szITEM sizeof(struct TItem)
char fileDict[szSTRN];
typedef struct TItem {
char word[szWORD];
char mean[szSTRN];
} Item;
fpos_t lookup(char *word, char *mean)
{
FILE * f = 0; Item i;
int r = 0; fpos_t p = 0;
if(!word) return 0;
f = fopen(fileDict, "rb");
if (!f) return 0;
while(!feof(f)) {
fgetpos(f, &p);
r = fread(&i, szITEM, 1, f);
if(r < 1) break;
if(i.word[0] == 0) continue;
if(strcmp(i.word , word)) continue;
if(mean) strcpy(mean, i.mean );
fclose(f);
return p+1;
}
fclose(f);
return 0;
}
void append(void)
{
Item i; FILE * f = 0; fpos_t p = 0;
memset(&i, 0, szITEM);
printf("请输入单词:"); scanf("%s", i.word );
p = lookup(i.word, 0 );
if(p) {
printf("字典内已经有该单词记录!\n");
return;
}
printf("请输入释义,按回车结束:");
fflush(stdin);
gets(i.mean );
f = fopen(fileDict, "ab");
fwrite(&i, szITEM, 1, f);
fclose(f);
printf("词条已新增\n");
}
void erase(void)
{
Item i; FILE * f = 0; fpos_t p = 0;
memset(&i, 0, szITEM);
printf("请输入单词:"); scanf("%s", i.word );
p = lookup(i.word, 0 );
if(p==0) {
printf("字典内没有该单词记录!\n");
return;
}
p--;
memset(&i, 0, szITEM);
f = fopen(fileDict, "rb+");
fsetpos(f, &p);
fwrite(&i, szITEM, 1, f);
fclose(f);
printf("词条已删除\n");
}
void edit(void)
{
Item i; FILE * f = 0; fpos_t p = 0;
memset(&i, 0, szITEM);
printf("请输入单词:"); scanf("%s", i.word );
p = lookup(i.word, 0 );
if(p==0) {
printf("字典内没有该单词记录!\n");
return;
}
p--;
printf("请输入释义,按回车结束(输入abort放弃修改):");
fflush(stdin);
gets(i.mean );
if(strstr(i.mean ,"abort")) {
printf("已放弃修改!\n");
return ;
}
f = fopen(fileDict, "rb+");
fsetpos(f, &p);
fwrite(&i, szITEM, 1, f);
fclose(f);
printf("词条已保存\n");
}
void query(void)
{
Item i; fpos_t p = 0;
memset(&i, 0, szITEM);
printf("请输入单词:"); scanf("%s", i.word );
p = lookup(i.word, i.mean );
if(p==0) {
printf("字典内没有该单词记录!\n");
return;
}
printf("【词条】%s\n【释义】%s", i.word , i.mean );
}
void set(void)
{
int cmd = 0;
printf("当前字典为%s,需要改变吗(选择y或Y改变)?", fileDict);
cmd = getch();
if(cmd == 'y' || cmd == 'Y') {
printf("请输入字典文件名称(包含路径):");
scanf("%s", fileDict);
printf("设置成功!\n");
}
}
int main(int argc, char * argv[])
{
int cmd = 0;
if(argc >1)
strcpy(fileDict, argv[1]);
else
strcpy(fileDict, "c:\\dict.txt");
/*end if*/
for(;;) {
printf("\n\
************************\n\
** 欢迎使用迷你字典!**\n\
************************\n\
** 0 - 设置字典 **\n\
** 1 - 查询词条 **\n\
** 2 - 新增词条 **\n\
** 3 - 编辑词条 **\n\
** 4 - 删除词条 **\n\
** 5 - 退出字典 **\n\
************************\n");
cmd = getch() - '0';
switch(cmd) {
case 0: set(); break;
case 1: query(); break;
case 2: append(); break;
case 3: edit(); break;
case 4: erase(); break;
default: return 0;
}
}
return 0;
}
㈣ C语言编程题,设计英汉词典的课设题型
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
#define min(A,B) (A<B?A:B)
#define max(A,B) (A<B?B:A)
typedef struct Dict
{
char en[30];
char zh[30];
struct Dict* next;
} Dict;
int main(void)
{
Dict* head = 0;
int stucount=0;//数量
while(1)
{
printf("输入操作号:1:词汇输入 2:浏览 3:汉英 4:英汉 5:删除 6:退出:");
int quest;
scanf("%d",&quest);
scanf("%*[^ ]");
if(quest==6)break;
else if(quest==1)
{
Dict* newDict = (Dict*)malloc(sizeof(Dict));
printf("请输入中文:");
scanf("%29s", newDict->zh);
scanf("%*[^ ]");
printf("请输入英文:");
scanf("%29s", newDict->en);
scanf("%*[^ ]");
//插入链表首,这样最新添加的显示在最上面,容易看见效果
newDict->next=head;
head=newDict;
++stucount;
}
else if(quest==2)
{
if(head==0)
printf("没有单词! ");
else
{
printf("开始浏览单词: ");
while(1)
int st=0,en=min(st+10,stucount);
{
printf("浏览:%d个到%d个单词 ",st+1,en);
Dict* stu = head;
for(int i=0; i<st; ++i)
{
stu=stu->next;
}
for(int i=st; i<en; ++i)
{
printf("中文:%s 英文:%s ",stu->en,stu->zh);
stu=stu->next;
}
printf("输入操作号:1 向后翻页;2 向前翻页;-1 退出:");
int squest;
scanf("%d",&squest);
scanf("%*[^ ]");
if(squest==1)
{
if(en!=stucount) st=en;
}
else if(squest==2)
{
st=max(0,st-10);
}
else if(squest==-1)break;
en=min(st+10,stucount);
}
}
}
else if(quest==3 || quest==4 || quest==5)
{
char a[30];
if(quest==3)printf("请输入汉语词汇:");
else if(quest==4) printf("请输入英语词汇:");
else if(quest==5) printf("请输入待删除的词汇(汉英均可):");
scanf("%29s", a);
scanf("%*[^ ]");
Dict* stu = head;
Dict* lststu = 0;
int flag=0;
while(stu!=0 && flag==0)
{
if(quest==3)
{
if(strcmp(a,stu->zh)==0)
{
printf("英语为:%s ",stu->en);
flag=1;
}
}
else if(quest==4)
{
if(strcmp(a,stu->en)==0)
{
printf("汉语为:%s ",stu->zh);
flag=1;
}
}
else if(quest==5)
{
if(strcmp(a,stu->en)==0 || strcmp(a,stu->zh)==0)
{
stucount--;
if(lststu!=0)
lststu -> next = stu -> next;
else
head = stu -> next;
printf("已删除! ");
flag=1;
}
}
lststu=stu;
stu=stu->next;
}
if(flag==0)
{
printf("没有查到词汇! ");
}
}
}
return 0;
}
你看看对不对,能不能跑吧。如果有新的需求我可以继续写。代码应该很清晰了,如果你哪不懂可以给你解释。欢迎追问。
㈤ 怎样用c语言编写英汉词典
用c语言最好用上数据库,sqlite3是用c语言写的开源数据库,Windows下、Linux下都能用,你可以用它。
㈥ C语言编写英汉词典
兄弟 分太少了 那么浪费时间。。。。
㈦ 用c语言编写电子英汉词典。
为了保证效率,建议使用哈希结构或者2岔树结构。
只需要提供插入删除和检索功能就可以了。
另外为字典的每个单元定义一个结构。
可以包含左右指针,自己的名词,及解释,还可以有其他东西。
然后实现树型结构的删除和检索功能就可以了。这个在数据结构的书上有吧。
然后写一个主函数就可以了。
㈧ 如何制作一个c语言的词典
以前写过一个类似的。
#include<stdio.h>
#include<string.h>
int main()
{
char *en[]={"airport",
"detective",
"parcel",
"diamond",
"stone",
"sand",
"flower",
"vegetable",
"pool",
"minute"};
char *ch[]={"飞机场",
"侦探",
"包裹",
"钻石",
"石头",
"沙",
"花",
"蔬菜",
"水池",
"分钟"};
int i,k=-1; //i作为循环变量,k保存字符串比较后的结果,初始值为-1
char s[20]; //s用来保存用户输入的单词
char **p=en; //定义一个指向指针的指针p,将它的值初始化为数组en的地址
printf("目前词库中仅收录了如下单词:\n");
for (i=0;i<10;i++)
{
puts(*p);
*p++;
}
printf("请输入一个单词,会给出该单词的解释:");
gets(s);
p=en;
for (i=0;i<10;i++)
{
if (strcmp(s,*p)==0)
{
k=i;
break;
}
*p++;
}
if (k!=-1)
printf("%s的意思是:%s\n",*p,ch[k]);
else
printf("该词库没有收录%s这个单词。\n",s);
return 0;
}
㈨ C语言编写词典
用多级链表把单词读到内存中,最好是按字母顺序,第一层就按字母a-z,每个字母存一个节点,下面一层用单链表存单词(可以试试按字母的多少,分别建单独的链表,这样可以提高检索的效率吧)。图片随便画的,大概就这么个意思吧。希望对你有帮助。
㈩ 如何用C语言编译电子词典
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>#define szWORD 32
#define szSTRN 224
#define szITEM sizeof(struct TItem)
char fileDict[szSTRN];typedef struct TItem {
char word[szWORD];
char mean[szSTRN];
} Item;fpos_t lookup(char *word, char *mean)
{
FILE * f = 0; Item i;
int r = 0; fpos_t p = 0;
if(!word) return 0;
f = fopen(fileDict, "rb");
if (!f) return 0;
while(!feof(f)) {
fgetpos(f, &p);
r = fread(&i, szITEM, 1, f);
if(r < 1) break;
if(i.word[0] == 0) continue;
if(strcmp(i.word , word)) continue;
if(mean) strcpy(mean, i.mean );
fclose(f);
return p+1;
}
fclose(f);
return 0;
}void append(void)
{
Item i; FILE * f = 0; fpos_t p = 0;
memset(&i, 0, szITEM);
printf("请输入单词:"); scanf("%s", i.word );
p = lookup(i.word, 0 );
if(p) {
printf("字典内已经有该单词记录!\n");
return;
}
printf("请输入释义,按回车结束:");
fflush(stdin);
gets(i.mean );
f = fopen(fileDict, "ab");
fwrite(&i, szITEM, 1, f);
fclose(f);
printf("词条已新增\n");
}void erase(void)
{
Item i; FILE * f = 0; fpos_t p = 0;
memset(&i, 0, szITEM);
printf("请输入单词:"); scanf("%s", i.word );
p = lookup(i.word, 0 );
if(p==0) {
printf("字典内没有该单词记录!\n");
return;
}
p--;
memset(&i, 0, szITEM);
f = fopen(fileDict, "rb+");
fsetpos(f, &p);
fwrite(&i, szITEM, 1, f);
fclose(f);
printf("词条已删除\n");
}void edit(void)
{
Item i; FILE * f = 0; fpos_t p = 0;
memset(&i, 0, szITEM);
printf("请输入单词:"); scanf("%s", i.word );
p = lookup(i.word, 0 );
if(p==0) {
printf("字典内没有该单词记录!\n");
return;
}
p--;
printf("请输入释义,按回车结束(输入abort放弃修改):");
fflush(stdin);
gets(i.mean );
if(strstr(i.mean ,"abort")) {
printf("已放弃修改!\n");
return ;
}
f = fopen(fileDict, "rb+");
fsetpos(f, &p);
fwrite(&i, szITEM, 1, f);
fclose(f);
printf("词条已保存\n");
}void query(void)
{
Item i; fpos_t p = 0;
memset(&i, 0, szITEM);
printf("请输入单词:"); scanf("%s", i.word );
p = lookup(i.word, i.mean );
if(p==0) {
printf("字典内没有该单词记录!\n");
return;
}
printf("【词条】%s\n【释义】%s", i.word , i.mean );
}void set(void)
{
int cmd = 0;
printf("当前字典为%s,需要改变吗(选择y或Y改变)?", fileDict);
cmd = getch();
if(cmd == 'y' || cmd == 'Y') {
printf("请输入字典文件名称(包含路径):");
scanf("%s", fileDict);
printf("设置成功!\n");
}
}
int main(int argc, char * argv[])
{
int cmd = 0;
if(argc >1)
strcpy(fileDict, argv[1]);
else
strcpy(fileDict, "c:\\dict.txt");
/*end if*/
for(;;) {
printf("\n\
************************\n\
** 欢迎使用迷你字典!**\n\
************************\n\
** 0 - 设置字典 **\n\
** 1 - 查询词条 **\n\
** 2 - 新增词条 **\n\
** 3 - 编辑词条 **\n\
** 4 - 删除词条 **\n\
** 5 - 退出字典 **\n\
************************\n");
cmd = getch() - '0';
switch(cmd) {
case 0: set(); break;
case 1: query(); break;
case 2: append(); break;
case 3: edit(); break;
case 4: erase(); break;
default: return 0;
}
}
return 0;
}