Hey guys..
I'm implementing a simple hash function to test my hash table ... but when i compute value for the hash value, i get this error of which i've never encountered, if i remember
Code:
Floating point exception
Here's wat's my functions look like
Code:
static void
hashtable_insert(HashTable *ht, char *key, char *value)
{
int tablefull = 0;
int hashval;
hashval = hash_func(key, value, ht);
tablefull = hashval;
int init_hashval = hashval;
if(key == '\0')
{
strcpy(ht->table[hashval].key, key);
strcpy(ht->table[hashval].value, value);
}
else
{
while(key != '\0')
{
if(tablefull == ht->num_items)
{
hashval = 0;
tablefull = 0;
}
strcpy(ht->table[hashval+1].key, key);
strcpy(ht->table[hashval+1].value, value);
tablefull++;
if(hashval == init_hashval)
{
perror("Table overflow!!\n");
exit(EXIT_FAILURE);
}
}
}
}
int hash_func(char *key, char *value, HashTable *ht)
{
int i, hashval, num_items;
num_items = ht->num_items;
for(i=0; i == '\0'; i++)
{
hashval = (int)(key+i) + (int)(value+i);
}
hashval = hashval % num_items;
return (int)hashval;
}
thx