I want to make a hashtable in c, where the keys are integers and the values are strings
I have a 2D char array in a struct, as follows in hashtable.h file:
#ifndef hashtable
#define hashtable
// define the maxmium size
#define INITIAL_SIZE 5
#define LOAD_FACTOR 0.7
typedef struct hashtable
{
int* keyArray[INITIAL_SIZE];
char* valueArray[INITIAL_SIZE][101]; // strings have maximum of 100 chars
bool isActiveArray[INITIAL_SIZE]; // for deleting elements
int count;
int capacity;
double loadFactor;
// true: linear probing, false: quadratic probing
bool collisionHandler;
} table;
#endif
I am trying to initialize the values of the arrays outside of the struct, like so
void initTable(table* p) {
// constructor
p->count = 0;
p->capacity = INITIAL_SIZE;
p->loadFactor = LOAD_FACTOR;
p->collisionHandler = true;
p->keyArray = {NULL};
p->valueArray = {{NULL}};
p->isActiveArray = {false};
}
however i receive these errors:
In file included from HashTable.c:22:0:
functions.h: In function 'initTable':
functions.h:85:16: error: expected expression before '{' token
p->keyArray = {NULL};
^
functions.h:86:18: error: expected expression before '{' token
p->valueArray = {{NULL}};
^
functions.h:87:21: error: expected expression before '{' token
p->isActiveArray = {false};
note: p is a pointer to my table struct
I want to know how to make a 2D array of all NULL values in the char* array, like
{{NULL}, {NULL}, {NULL}} also to use for comparison later on like trying to insert a value into the valueArray, and checking if null
I also want to make the keyArray, the int* list to be like {NULL, NULL, NULL} instead of a random memory address so I can easily check for a NULL pointer, and then replace it with a pointer to an int when making a new key/value pair