91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

用C語言做的字典程序,中使用鏈表和結構體,涉及的知識點有結構體,指針,鏈表的添加,遍歷,刪除,釋放,文件的打開,讀取,關閉等。使用Xcode寫的代碼,可以在Xcode4.2中直接運行,但是需要更改字典數據文件的路徑,也可以在終端下編譯運行,也可以直接把main.C拷貝到vc下去運行

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#define?TRANS_LEN?1024
#define?WORD_LEN?32
struct?Dict{
????char?name[WORD_LEN];
????char?trans[TRANS_LEN];
????/*單鏈表,存放下一個節點的指針*/
????struct?Dict?*next;
};
void?cal_time(struct?timeval?*prev?struct?timeval?*cur);
void?cal_time(struct?timeval?*prev?struct?timeval?*cur)
{
time_t?s;
suseconds_t?m;
s?=?cur->tv_sec?-?prev->tv_sec;
m?=?cur->tv_usec?-?prev->tv_usec;
m?+=?s*1000000;
printf(“time:%f(ms)\n“?(double)m?/?1000);
}

//插入數據節點
void?insertDict(struct?Dict?*headchar?*dictWordchar?*dictTrans);
void?insertDict(struct?Dict?*headchar?*dictWordchar?*dictTrans)
{
????//創建一個節點存儲每一行數據
????struct?Dict?*node=malloc(sizeof(struct?Dict));
????strcpy(node->namedictWord);
????strcpy(node->transdictTrans);
????node->next=NULL;
????
????//將節點添加到頭節點和第一個節點之間
????node->next??=?head->next;
????head->next?=?node;
}
//釋放鏈表
void?deleteDictlinkdelist(struct?Dict?*head){
????struct?Dict?*p?=?head;
????while?(p)?{
????????struct?Dict?*tmp?=?p->next;
????????free(p);
????????p=tmp;
????}
????head->next=NULL;
}

/*使用結構體數組來存放字典數據*/
//struct?Dict?dicts[100000]={};

/*讀取字典文件*/
/*讀取字典文件-函數聲明*/
void?findTrans(struct?Dict?*head);
void?findTrans(struct?Dict?*head){
????/*讀取字典文件*/
????FILE?*fp?=?fopen(“/dict.txt““r“);????
????if?(fp!=NULL)?{
????????char?dictLine[TRANS_LEN]={};
????????/*讀取字典的每一行*/
????????int?dict_i=0;
????????while?(fgets(dictLineWORD_LENfp))?{
????????????int?i;
????????????int?j;
????????????char?dictWord[WORD_LEN]={};
????????????/*獲得單詞*/??
????????????for?(i=0j=1;j<(strlen(dictLine)-1);i++j++)?{
????????????????dictWord[i]=dictLine[j];
????????????}
????????????memset(dictLine0WORD_LEN);
????????????fgets(dictLineTRANS_LENfp);
????????????char?dictTrans[TRANS_LEN]={};
????????????/*獲得單詞的解釋*/
????????????for?(i=0j=6;j<(strlen(dictLine)-1);i++j++)?{
????????????????????dictTrans[i]=dictLine[j];
????????????}
?
????????????/*使用鏈表來存放字典數據*/
????????????insertDict(headdictWorddictTrans);
????????????
????????????/*使用結構體數組存放字典數據*/
????????????//strcpy(dicts[dict_i].namedictWord);
????????????//strcpy(dicts[dict_i].transdictTrans);
????????????dict_i++;
????????}
????}else{
????????printf(“file?not?found“);
????}
????//關閉打開的文件流
????fclose(fp);
}
int?main?(int?argc?const?char?*?argv[])
{
????//創建頭節點,不要忘記為節點分配內存,分配內存的時候使用sizeof(數據類型)
????struct?Dict?*head?=?malloc(sizeof(struct?Dict));
????//調用函數,讀取字典文件,并將字典數據分割后加載進鏈表
????struct?timeval?prev?cur;
gettimeofday(&prev?NULL);
????findTrans(head);
????gettimeofday(&cur?NULL);
cal_time(&prev?&cur);//統計詞庫加載時間
????//輸入的單詞
????char?word[WORD_LEN]={};
????char?trans[TRANS_LEN]={};
????while?(1)?{
????????//遍歷鏈表查找單詞的釋義
????????struct?Dict?*p=head->next;
????????printf(“請輸入英文單詞(輸入:exit退出):\n“);
????????scanf(“%s“word);
????????if?(strcmp(word“:exit“)==0)?{
????????????break;
????????}
????????while?(p)?{
????????????if?(strcmp(p->nameword)==0)?{
????????????????strcpy(transp->trans);
????????????????printf(“%s\

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????6148??2013-04-18?19:58??ProjectDictionary\.DS_Store

?????文件???????6148??2013-04-18?19:58??ProjectDictionary\ProjectDictionary\.DS_Store

?????文件????2007645??2011-04-19?15:06??ProjectDictionary\ProjectDictionary\dict.txt

?????文件???????3762??2013-04-18?20:34??ProjectDictionary\ProjectDictionary\main.c

?????文件???????3140??2013-04-15?09:32??ProjectDictionary\ProjectDictionary\ProjectDictionary.1

?????文件???????6711??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj\project.pbxproj

?????文件????????162??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj\project.xcworkspace\contents.xcworkspacedata

?????文件??????13286??2013-04-18?20:34??ProjectDictionary\ProjectDictionary.xcodeproj\project.xcworkspace\xcuserdata\qianfeng.xcuserdatad\UserInterfaceState.xcuserstate

?????文件?????????91??2013-04-15?15:30??ProjectDictionary\ProjectDictionary.xcodeproj\xcuserdata\qianfeng.xcuserdatad\xcdebugger\Breakpoints.xcbkptlist

?????文件???????3160??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj\xcuserdata\qianfeng.xcuserdatad\xcschemes\ProjectDictionary.xcscheme

?????文件????????489??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj\xcuserdata\qianfeng.xcuserdatad\xcschemes\xcschememanagement.plist

?????目錄??????????0??2013-04-18?20:34??ProjectDictionary\ProjectDictionary.xcodeproj\project.xcworkspace\xcuserdata\qianfeng.xcuserdatad

?????目錄??????????0??2013-04-15?15:30??ProjectDictionary\ProjectDictionary.xcodeproj\xcuserdata\qianfeng.xcuserdatad\xcdebugger

?????目錄??????????0??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj\xcuserdata\qianfeng.xcuserdatad\xcschemes

?????目錄??????????0??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj\project.xcworkspace\xcuserdata

?????目錄??????????0??2013-04-15?10:42??ProjectDictionary\ProjectDictionary.xcodeproj\xcuserdata\qianfeng.xcuserdatad

?????目錄??????????0??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj\project.xcworkspace

?????目錄??????????0??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj\xcuserdata

?????目錄??????????0??2013-04-18?20:34??ProjectDictionary\ProjectDictionary

?????目錄??????????0??2013-04-15?09:32??ProjectDictionary\ProjectDictionary.xcodeproj

?????目錄??????????0??2013-04-18?14:51??ProjectDictionary

-----------?---------??----------?-----??----

??????????????2050742????????????????????21


評論

共有 條評論