I have this function:
static pair_t * // not visible outside this file
pair_new(const int key)
{
pair_t *pair = malloc(sizeof(pair_t));
if (pair == NULL) {
// error allocating memory for pair; return error
return NULL;
} else {
printf("key is %d\n",key);
*(pair->key) = key;
*(pair->count) = 1;
pair->next = NULL;
return pair;
}
}
but the way I am trying to dereference the key element of the instance of pair is giving me a seg fault. I think it is because 'pair' is a pointer.
the pair structure is defined as follows:
typedef struct pair {
int *key; // search key for this item
int *count; // pointer to data for this item
struct pair *next; // children
} pair_t;
Any suggestions on how to properly change the value of key would be much appreciated