Hashing

This program is supposed to take in 15 words input by the user and hash them into an array and print out the array with "??" in the empty spots of a 23 length array. I am having trouble storing the information. What am I doing wrong?




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main(void)
{
char a[50];
string hashed[23];
string question;
int hash;
int i, c;
string word;
question="??";

for (i=0;i<23;i++)
  {
  hashed[i]="??";
  }
for (i=0;i<23;i++)
  {
  cout<<hashed[i]<<endl;
  }

i=0;
c=0;
while(c<15)
{
c++;
cout<<"Enter a word"<<endl;
cin>>a;

word=a;
hash=(a[0] + a[strlen(a)-1])%23;

cout<<"word is "<<word<<endl;
cout<<"hash is "<<hash<<endl;

i=hash;

if(hashed[i]==question)
  {
  cout<<"it is empty"<<endl;
  hashed[i]=word;
  }

else
  {
  cout<<"it is not empty"<<endl;
  i++;
  }
}
cout<<hashed<<endl;

return 0;
}
char stores 1 letter so itll probably work if u change the char to a string
Topic archived. No new replies allowed.