还是看代码, 代码里面加入了一些调试程序:
#include <stdio.h>
#include<string.h>
#define Index int
Index Hash(char *key , int len , int TableSize)
{
unsigned int HashVal = 0;
int j;
printf("in the index hash \n");
for(j = 0 ; j<len ; ++j)
{
printf("%c\n" , *key++);
}
while(*key != '\0')
{
printf("%c\n" , *key);
HashVal += *key++;
}
printf("the hashval is %d\n" , HashVal);
return HashVal % TableSize;
}
int main()
{
//char key_str[] = "this is my program";
char *key_str;
key_str = malloc(sizeof(char)*20);
strcpy(key_str , "this is my program");
int ret , len ,i;
len = strlen(key_str);
printf("%d\n" , len);
for(i=0;i<len;++i)
{
printf("%c\n", key_str[i]);
}
printf("*********");
printf("\n");
ret = Hash(key_str , len , 10);
printf("%d\n" , ret);
return 0;
}
自从看到尼纳斯狂贬c++后,再也不碰c++了,c++确实是一门很恐怖的语言,设计糟糕透顶。看了编程人生后,很多程序员对c++感到很厌恶,天才都这么说了,我等凡夫俗子,还是不要耗在c++上了,毕竟一个人一生精力有限。更何况,c++现在也是一门快要死的语言。