Working on speller and have to stop, but would like some help on where I'm stuck. So far, have decided to go with a hash table approach.
Assume: 1) I've already created a 2d massive array to store words as my hash table
In load, I 1) read from the file char by char into an array 2) terminate with /0
Now I'd like to: 1) hash the 'word' 2) Store the word in my hash table
A couple related questions: 1) Do I have to malloc to store the word? 2) Can I pass the word directly from the array to my hash function and into my table?
My thinking is that since I already have the characters stored in memory, I should somehow be able to pass it to the hash function, get the key, and then just strcpy it into the array without an intermediate step of malloc'ing. Since the array is already allocated, this would save a bunch of time.
But I find a couple problems in advance: each word will be a different length; if I just create max length, I think the 'null' bytes will effect the hash function, since it is based on length of the input; also, the array variable itself is just a pointer to the beginning of the string of characters. I don't know how I can pass the full word into the hash function.
Since I'm relying on the hash function returning the same result, I need to get this right, but feel like I'm not understanding exactly how the stack memory works here, and what tools I have to copy from the stack memory into other functions and parts of the program.
Thanks for any help!