I’m trying to use a file pointer that I have declared in a structure of linked list, but I keep getting it as a NULL value.
I have the following structure:
struct _hash_table
{
char found;
struct _hash_chain *hash_chain;
}
struct _hash_chain
{
uint64_t value;
FILE *fout;
struct _hash_chain *next;
}
and
struct _hash_table hash_table[TABLE_SIZE];
I keep getting hash_table[i]->hash_chain->fout = NULL and it’s pointer address is nil.
Do I need to dynamically allocate memory for the pointer?
struct _hash_table hash_table[TABLE_SIZE];– This will not allocate memory forstruct _hash_chainbecausehash_chainis pointer variable in_hash_table.Accssing
h_table[i].hash_chainwithout dynamic memory allocation will leads to crash(an undefined behaviour). I hope you will take care ofnextpointer.