0

I'm using a hash function I found online that's meant to be quick but it's throwing an error that I don't understand (and as I've cut and paste it, I don't get what the issue can be?). Everything else is working (I used a different hash function initially to test it).

int hash_function(const char* word)
{
unsigned int hash = 0;
for (int i = 0, n = strlen(word); i < n; i++)
    hash = (hash << 2) ^ word[i];
return index % HASHSIZE;
}

The error its throwing me is:

dictionary.c:42:18: error: invalid operands to binary expression ('char *(*)     (const char *, int)' and 'int')
return index % HASHSIZE;
       ~~~~~ ^ ~~~~~~~~
1 error generated.
make: *** [dictionary.o] Error 1

Any idea what's wrong? This is the third hash function I've tried to use that hasn't worked once I've put it into my code so I'm obviously missing something!

1

The code will return index % HASHSIZE;, but where is index calculated? Maybe index was supposed to be hash?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Oh I'm such an idiot! Thank you!
    – MelJ79
    Jul 3 '16 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .