I need to produce a hash value for a given word. the hash value need to be deterministic, or the same value for the same word, however if the given word has an different cases the hash value changes.
So my objective is to convert the given word (const char) to a lower case witin the hash function, in order to obtain always the same hash code regardless the case.
I have the following code:
#define LENGTH 45
const unsigned int N = 7703;
unsigned int hash(const char *word);
text = "aardvark's"; //given word this can have upper and lower cases
s = hash(text);
printf("hash or text: %d
unsigned int hash(const char *word) // the given word is constant char
unsigned long h;
unsigned char *str = (char*)word;
h = 0;
while(*str != '')
*str = tolower(*str); //trying to convert to lower cases
h = (h * LENGTH + *str) % N;
I have tried the above as well as different combinations, but i keep getting errors, the main error is 'segmentation fault core dumped', but using different code arrangement i get error: 'makes pointer from integer without a cast'.
Can you please advise how to resolve this? as I am stuck, many thanks.