A hash table is meant to look up an entry in a collection by key in constant time. In terms of implementation this typically consists of a "hidden" array of object pointers (not the objects themselves). You then need a hashing function that converts a key into an array lookup index (integer). As an example:
ValueObjectType **createHashTable(int hashSize)
{
ValueObjectType **table = malloc( sizeof(ValueObjectType *) * hashSize);
return table;
}
void hashInsert(ValueObjectType **hashTable, KeyObjectType key, ValueObjectType *value)
{
int arrayIndex = hashingFunction(key);
if ( hashTable[arrayIndex] != NULL ) traverseLinkedListAndAdd(...);
else hashTable[arrayIndex] = value;
}
ValueObjectType *lookupByKey(ValueObjectType **hashTable, KeyObjectType key)
{
int arrayIndex = hashingFunction(key);
return traverseLinkedListAndReturnObjectWithKey(...);
}
A hashing function usually involves taking one or more key elements (which can be of any type) and converting them to a single integer value and then converting that to an array index by taking the modulo of the hash array size.
The purpose for the linked list in your Book struct is to deal with hash collisions. A hash collision occurs on insert either because the given key already exists in the hash (in which case you should replace the value object reference with the new object) or because of the non-uniqueness of the hashing function. When the latter happens, the linked list is used to store multiple entries with different keys that hash to the same array index (typically by iterating through the list, replacing an element of the list if key equality is seen, and otherwise tacking the new object on at the end).
In the example code above I have a separate key object, but in order to evaluate equality of the key it needs to be either included in the object itself (I suspect in your case the key is some combination of title and author), or wrapped in a meta structure (such as a "KeyValue" struct that contains a pointer to the key and the value, which you would hash instead of ValueObjectType). You need to provide logic to evaluate equality/inequality of two keys in order to properly handle the hash collision case.
I've left the hashing function, linked list navigation, and key equality logic unspecified here because this is clearly what your instructor wants you to learn how to do.
memsetcall aftermalloc, or replacemallocwithcalloc(which zeroes the memory it allocates).is that a correct syntax?- well why do you ask? why don't you try compiling it? if it compiles, the syntax is correct.