看板 C_and_CPP 關於我們 聯絡資訊
DEV C 問題(Question): 版上的大大好,想要弄一個簡單的雜湊表去儲存一篇文章 計算這篇文章 某個單字出現過幾次 雜湊值的算法是開頭字的ASCII碼*最後一個字的ASCII碼 想問的是,我想要存成一個二維的陣列 hash[i][0]用來存雜湊值 slot[i][j]用來存雜湊值相同的單字 可是資料型態一直錯誤... 可以請版上的大大們糾正一下小弟的指標嘛.... 程式碼(Code):(請善用置底文網頁, 記得排版) char slot[100][100]={" "}; int hash[100][100]={0}; int main(){ FILE *pFile; char mystr [100000]; pFile = fopen("程式2-文章短138-750.txt","r"); if (pFile == NULL) perror ("這個檔案錯誤"); else { fgets(mystr , 100000 , pFile); puts (mystr); fclose(pFile); char *pch; pch = strtok(mystr," ,.-;"); while (pch != NULL){ printf ("%s\n",pch); total= (pch[0]*pch[strlen(pch)-1]) ; printf ("%d\n",total); while (hash[i][0] !=0){ if (slot[i][0]=total){ while (*slot[i][j]==" "){ j=j+1; strcpy(*slot[i][j],*pch); } } i=i+1; } hash[i][0]=total; strcpy(*slot[i][1],*pch); i=0; total = 0; pch = strtok(NULL," ,.-;"); } } ※ 編輯: psychic 來自: 210.209.142.134 (04/18 22:26) ※ 編輯: psychic 來自: 210.209.142.134 (04/18 22:26)
firejox:轉型一下 雖然不見得有效 04/18 22:30
firejox:在相乘地方 04/18 22:30
psychic:不好意思 可以請問一下轉型式什麼嗎?@@" 相乘的地方? 04/18 22:32
psychic:total變數嗎? 04/18 22:32
firejox:對 04/18 22:34
psychic:不好意思 可以講得更清楚一點嗎? 轉型?剛接觸C不久.... 04/18 22:40
psychic:轉型是重新定義?? 04/18 22:40
firejox:痾...不是 而是將型態暫時改變 04/18 22:56
firejox:比方說char變int int變double等 04/18 22:57
firejox:用法是(型別)運算式 04/18 23:03
psychic:大大不好意思,其實我剛接觸不久...不懂怎麼轉型... 04/19 07:00
hnaxiorll:char a = 'A'; int b; b = (int)a; 04/21 11:58
hnaxiorll:這樣就是把字元型態 暫時轉成int傳過去 04/21 11:59