I'm trying to implement the fnv1a hash function on all the words from a dictionary (so I can access them quickly later on).
This is the fnv1a hash function:
int
fnv1a(unsigned char byte, uint32_t hash)
{
hash = SEED;
// SEED is a constant that I defined
return ((byte ^ hash) * PRIME) % HASHTABLE_SIZE;
}
And this is how I'm trying to get the hash for a word in a function called load():
int hash = fnv1a((unsigned char)*(ptr->word)++, SEED);
Here's the full function:
/* * Loads dictionary into memory. Returns true if successful else false. */
bool
load(const char *dictionary)
{
FILE* fp = fopen("words.txt", "r");
// make new node to store the stuff in
node *ptr = malloc(sizeof(node));
ptr->next = NULL;
// while it's not the end of the file
while(!feof(fp))
{
// store the word in the ptr
fscanf(fp, "%s", ptr->word);
// get hash function for word
int hash = fnv1a((unsigned char)*(ptr->word)++, SEED);
// store word at hash value in hashtable
// if there isn't a word there yet
if (hashtable[hash]->next == NULL)
hashtable[hash]->next = ptr;
// else go to the end of the list and add the word
// haven't done this part yet
if (hashtable == NULL)
{
printf("Didn't work out, bud");
return false;
}
else
return true;
}
The error that I keep getting when I compile this code (points to the line with me trying to hash a word):
dictionary.c:70:53: error: lvalue required as increment operand
word
inptr->word
? - Tony The Lionchar []
. - user529758char[]
don't haveoperator++
defined on them. - Tony The Lion