You can solve this by casting to the expected type:
int wordvalue = hash((unsigned char *)buffer);
Another option is performing the cast inside your
hash()
function:
unsigned long hash(char *str)
{
unsigned long hash = 5381;
unsigned char c = 0;
while (c == (unsigned char)*str++)
{
hash = ((hash << 5) + hash) + c;
}
return hash;
}
Note that I have used the type
unsigned char
for the variable
c
here too. While this is not really necessary it indicates more clear that unsigned values are used.