I started my load function without looking at any reference code (first time starting a pset this way) to give me an idea on how to implement my own version. I was mostly confident until I reached the hash function inside of load. I couldn't figure out what to do exactly so I thought i'd move onto the hash function and come back to hash in load when I figured how to implement the function but I quickly got confused while researching hash. I found this example:
int hash(const char * str) {
int hash = 401;
int c;
while (*str != '\0') {
hash = ((hash << 4) + (int)(*str)) % MAX_TABLE;
str++;
}
return hash % MAX_TABLE;
}
which was the easiest to follow for me but I am not sure where the 401 came from or what was going on in the brackets of the while loop. At this point I am not even sure I started the load function right. I know I still need to free the memory I allocated and finish the hash portion but I was hoping someone can look it over and tell me if I have made any errors, and see if that'll help me figure out how to start the hash function. I left notes and queston on my code for myself as well as in case I had to ask others, here is my code:
bool load(const char *dictionary)
{
// TODO
fopen(dictionary);
{
//Unsure if this works, may switch to if (load == false)
if ((fopen(dictionary) == NULL)
{
return false;
}
//Unsure if I can use the condition like this
for(int i = 0; return = 0; i++)
{
fscanf(dictionary, "%s", word)
{
int feof(*dictionary, dictionary);
{
//originally checked to see if feof was null then returned 0 until eof reached
while(!feof(dictionary))
{
//originally had char *word = malloc(sizeof (char)), do I need a new struct for new nodes?
//Or do I need to change the name of the word pointer to differentiate from the original char word in
//the node struct?
node *word = malloc(sizeof (node));
//originally had list as malloc, changed to list when reviewing notes,
//unsure if "if(malloc == NULL)"" would work
if (list == NULL)
{
return false;
}
strcpy(node, word);
return 0;
}
//Unsure how to implement this part yet
hash(word)
{
node-> index
}
}
}
}
}
return true;
}