Hi guys!
I defined a type like this:
typedef struct {
char *key;
int freq;
float pr;
} TableEntry;
and then I have an array of pointers to this struct:
TableEntry* hash_table[hash_table_size];
But it gives an error when I want to allocate memory for this array:
assert((hash_ta ble = malloc((hash_ta ble_size)*sizeo f(TableEntry))) !=NULL);
Do I need to allocate some memory for key before allocating memory for struct???and how I can allocate memory for a string without knowing its length???
Cheers
I defined a type like this:
typedef struct {
char *key;
int freq;
float pr;
} TableEntry;
and then I have an array of pointers to this struct:
TableEntry* hash_table[hash_table_size];
But it gives an error when I want to allocate memory for this array:
assert((hash_ta ble = malloc((hash_ta ble_size)*sizeo f(TableEntry))) !=NULL);
Do I need to allocate some memory for key before allocating memory for struct???and how I can allocate memory for a string without knowing its length???
Cheers
Comment