電子詞典的實現

2021-07-04 12:20:24 字數 1565 閱讀 5332

#define _crt_secure_no_warnings

#include

#include

#include

#include

#define max 111111 //最大記錄數

struct dict ;

//開啟字典檔案,並讀取檔案內容

int open_dict(struct dict **p, const char *dict_filename) ;

size_t len = 0;

int i = 0;//計數器

while (!feof(pfile))//迴圈讀取檔案,直到檔案末尾

memset(buf, 0, sizeof(buf));

fgets(buf, sizeof(buf), pfile);

len = strlen(buf);

if (len > 0)

i++;//計數器加1 }

fclose(pfile);//關閉字典檔案

return i;//返回讀取到的字典詞條數 }

//根據關鍵字key,在字典中查詢內容

int search_dict(const struct dict *p, int size, const char *key, char *content)

} return 0;//沒有找到符合條件記錄,返回0 }

//釋放記憶體

void free_dict(struct dict *p, int size)

free(p);//釋放p記憶體 }

int main(int argc, char *args)

long start_ms = 0;//記錄函式執行的開始時間

long end_ms = 0;//記錄函式執行的結束時間

struct dict *p = null;

start_ms = clock();

int dict_size = open_dict(&p, args[1]);//根據命令列第乙個引數做為字典檔名,開啟字典檔案

if (dict_size == 0)

return 0;//開啟字典檔案失敗,程式退出

end_ms = clock();

printf("open_dict used %ld ms\n", end_ms - start_ms);//列印函式執行時間,單位:毫秒

char key[1024];

char content[1024];

while (1)

else

end_ms = clock();

printf("search_dict used %ld ms\n", end_ms - start_ms);//列印函式執行時間,單位:毫秒 }

start_ms = clock();

free_dict(p, dict_size);

end_ms = clock();

printf("free_dict used %ld ms\n", end_ms - start_ms);//列印函式執行時間,單位:毫秒

return 0; }

mysql電子詞典 電子詞典

一 功能說明使用者可以登入和註冊 登入憑藉使用者名稱和密碼登入 註冊要求使用者必須填寫使用者名稱,密碼,其他內容自定 使用者名稱要求不能重複 要求使用者資訊能夠長期儲存可以通過基本的圖形介面print以提示客戶端輸入。程式分為服務端和客戶端兩部分 客戶端通過print列印簡單介面輸入命令發起請求 服...

簡易電子詞典

01 0203 0405 0607 0809 1011 1213 1415 1617 1819 2021 2223 2425 2627 2829 3031 3233 3435 3637 3839 4041 4243 4445 4647 4849 5051 5253 5455 5657 5859 60...

SQLite 電子詞典

伺服器部分 段 include include include include include include include include include include define n 16 define r 1 user register define l 2 user login def...