C語言實(shí)現(xiàn)電子英漢詞典系統(tǒng)
本文實(shí)例為大家分享了C語言實(shí)現(xiàn)電子英漢詞典系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、設(shè)計(jì)功能(文章僅供參考)
a. 詞條錄入:即添加單詞記錄。
b. 信息顯示:將所有的單詞按字母順序顯示。
c. 詞條修改:對已經(jīng)輸入的單詞信息進(jìn)行修改。
d. 詞條刪除:刪除某個(gè)單詞記錄。
e. 單詞查詢: 輸入單詞英文拼寫,輸出該單詞的中文釋義。
f. 信息保存:將單詞信息保存到文件。
g. 退出系統(tǒng)
二、功能展示
三、思維導(dǎo)圖
四、程序源碼
#include <stdio.h>?? ?//引入庫函數(shù) #include <stdlib.h> #include <string.h> #define szWORD 50?? ?//單詞長度最大50 #define szSTRN 200?? ?//釋義長度最大200 #define szProject sizeof(struct Dictionary) char fileDict[szSTRN]; typedef struct ? Dictionary{ char word[szWORD]; char mean[szSTRN]; } Project ; //定義字典結(jié)構(gòu)體,定義兩個(gè)字符型變量單詞和釋義 fpos_t consult(char *word, char *mean) { FILE * f = 0; Project ?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, szProject , 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 Search(void); void Append(void); void Delete(void); void Update(void); ? int main(int argk, char * argh[]) { int m= 0; if(argk>1)? ? strcpy(fileDict, argh[1]); else ? strcpy(fileDict, "c:\\dict.txt"); for(;;) { printf("\n\ --------------------\n\ 歡迎使用電子英漢詞典!\n\ --------------------\n\ 1 - 查詢詞條\n\ 2 - 新增詞條\n\ 3 - 刪除詞條\n\ 4 - 修改詞條\n\ 5 - 退出詞典\n\ --------------------\n"); ? m = getchar() - '0'; ? switch(m) { case 1: Search();break; case 2: Append();break; case 3: Delete();break; case 4: Update();break; default : return 0;} } return 0; } ? void Search(void) { ?Project i; fpos_t p = 0; memset(&i, 0, szProject ); printf("please input the word ?you want:"); scanf("%s", i.word ); p = consult(i.word, i.mean ); if(p==0) { ? printf("sorry do not find what you want!\n"); ? return; } printf("單詞:%s\n釋義:%s", i.word , i.mean ); } void Append(void) { Project ?i; FILE * f = 0; fpos_t p = 0; memset(&i, 0, szProject ); printf("please input the word you want:"); scanf("%s", i.word ); p = consult(i.word,0); if(p) ? ? { ? printf("sorry do not find what you want!\n"); ? return; } printf("please giving the meaning,按確認(rèn)結(jié)束:");? fflush(stdin); gets(i.mean ); f = fopen(fileDict, "ab"); fwrite(&i, szProject , 1, f); fclose(f); printf("詞條已新增\n"); } void Delete(void) { ?Project ?i; FILE * f = 0; fpos_t p = 0; memset(&i, 0, szProject ); printf("please input the word you want:"); scanf("%s", i.word ); p = consult(i.word, 0 ); if(p==0) { ? printf("sorry do not find what you want!\n"); ? return; } p--; memset(&i, 0, szProject); f = fopen(fileDict, "rb+"); fsetpos(f, &p); fwrite(&i, szProject , 1, f); fclose(f); printf("詞條已刪除\n"); } void Update(void) { ?Project ?i; FILE * f = 0; fpos_t p = 0;? memset(&i, 0, szProject ); printf("please input the word you want:"); scanf("%s", i.word ); p = consult(i.word, 0 ); if(p==0) { ? printf("sorry do not find what you want!\n"); ? return; } p--; printf("please giving the meaning,按確認(rèn)結(jié)束(輸入drop放棄修改):");? fflush(stdin); gets(i.mean ); if(strstr(i.mean ,"drop")) { ? printf("已放棄修改!\n"); ? return ; } f = fopen(fileDict, "rb+"); fsetpos(f, &p); fwrite(&i, szProject , 1, f); fclose(f); printf("詞條已保存\n"); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
c++ 預(yù)處理之正整型實(shí)現(xiàn)方法
這篇文章主要介紹了c++ 預(yù)處理之正整型實(shí)現(xiàn)方法,需要的朋友可以參考下2017-07-07C++實(shí)現(xiàn)保存數(shù)據(jù)至EXCEL
這篇文章主要介紹了C++實(shí)現(xiàn)保存數(shù)據(jù)至EXCEL,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11C++?JSON庫?nlohmann::basic_json::array?的用法示例詳解
nlohmann::json是一個(gè)C++的JSON庫,它提供了一種容易和直觀的方法來處理JSON數(shù)據(jù),nlohmann::json::array()是用來創(chuàng)建一個(gè)JSON數(shù)組的方法,這篇文章主要介紹了C++ JSON庫nlohmann::basic_json::array的用法,需要的朋友可以參考下2023-06-06C++11正則表達(dá)式詳解(regex_match、regex_search和regex_replace)
正則表達(dá)式(regular expression)是計(jì)算機(jī)科學(xué)中的一個(gè)概念,又稱規(guī)則表達(dá)式,下面這篇文章主要介紹了C++11正則表達(dá)式(regex_match、regex_search和regex_replace)的相關(guān)資料,需要的朋友可以參考下2022-09-09OpenCV實(shí)現(xiàn)圖像背景虛化效果原理詳解
相信用過相機(jī)的同學(xué)都知道虛化特效,這是一種使焦點(diǎn)聚集在拍攝主題上,讓背景變得朦朧的效果。本文將詳細(xì)介紹一些這一效果的實(shí)現(xiàn)原理以及代碼,需要的可以參考一下2022-03-03