[問題] 指標陣列使用
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)
→
04/18 22:30, , 1F
04/18 22:30, 1F
→
04/18 22:30, , 2F
04/18 22:30, 2F
→
04/18 22:32, , 3F
04/18 22:32, 3F
→
04/18 22:32, , 4F
04/18 22:32, 4F
→
04/18 22:34, , 5F
04/18 22:34, 5F
→
04/18 22:40, , 6F
04/18 22:40, 6F
→
04/18 22:40, , 7F
04/18 22:40, 7F
→
04/18 22:56, , 8F
04/18 22:56, 8F
→
04/18 22:57, , 9F
04/18 22:57, 9F
→
04/18 23:03, , 10F
04/18 23:03, 10F
→
04/19 07:00, , 11F
04/19 07:00, 11F
→
04/21 11:58, , 12F
04/21 11:58, 12F
→
04/21 11:59, , 13F
04/21 11:59, 13F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章