Code:
#include <iostream>
using namespace std;
unsigned hash(void *key, int len);
int main()
{
char key[20];
cout<<"String: ";
cin.getline(key, 20);
int len = 20;
cout<<"Hashed: "<<hash(key, len);
cin.ignore();
return 0;
}
unsigned hash(void *key, int len)
{
unsigned char *p = key;
unsigned h=0;
int i;
for(i=0; i<len; i++)
{
h=33*h+p[i];
}
return h;
}
The whole thing so there's no confusion
Here's the error:
c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\hash test 1\hash test 1\main.cpp(20) : error C2440: 'initializing' : cannot convert from 'void *' to 'unsigned char *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Thanks! =)