當前位置:首頁 » 編程語言 » c語言編程詞典
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言編程詞典

發布時間: 2022-07-11 01:56:57

㈠ 一種簡單英文詞典排版系統的實現 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;
}