I'm in the process of creating a hash table. I'm using a struct for the capacity, number of keys, frequencies and the keys themselves. Here is my code for initializing the struct:
htable htable_new(int capacity) {
htable result = emalloc(sizeof *result);
result->capacity = capacity;
result->frequencies = emalloc(capacity * sizeof result->frequencies[0]);
result->keys = emalloc(capacity * sizeof result->keys[0]);
result->frequencies = 0;
result->keys = NULL;
return result;
}
Now, from my understanding, a char** array is a pointer to an array of pointers (of type char)? So when I allocate memory, would it be correct to use keys[0]? I assume that this just represents the size of the char pointer? Which leads to my next question of when I actually set the keys in the array (which is obviously in another function) would I just allocate memory to each index by the size of the string I input before storing it?
i.e. h->keys[index] = emalloc(sizeof(str)
Thanks for your answers!