I have this exercise for homework that follows:
Consider the following definition to represent dynamic hashtables with collision treatment chaining.
typedef struct entry{
char key[10];
void *info;
struct entry *next;
} *Entry;
typedef struct hashT{
int hashsize;
Entry *table;
} *HashTable;
Define `HashTable newTable(int hashsize) note that the memmory necessary must be allocated and that all table entrys must be initialized with empty list.
My proposition is this:
HashTable newTable(int hashSize){
Entry *table = malloc(sizeof((struct entry)*hashSize));
HashTable *h = malloc(sizeof(struct hashT));
h->hashSize = hashSize;
h->table = table;
return h;
}
im pretty sure the logic is correct. my problem is with pointers. for example, sometime I see (char *), or in this case (table *) before the malloc function... Is this necessary?
and for the return, should I return h, or *h? and whats the difference?
thank you