0

I'm creating an array of queues and trying to initialize them by setting the fronts and backs to NULL. This works for the first two indexes (0 and 1) but if I go any further I just get a segmentation fault.

struct queue
{
    struct node *front;
    struct node *back;
};

struct node
{
    struct node *next;
    struct node *prev;
    int sequenceNumber;
};

void init(struct queue *qPtr);

int main()
{

    struct queue *theQueues[10];

    init(theQueues[0]);
    init(theQueues[1]);
    init(theQueues[2]); // I am getting a problem on this line

 }

void init(struct queue *qPtr)
{

    qPtr->front = NULL;
    qPtr->back = NULL;
}

  • You must assign pointers to valid buffers before dereferencing pointers. Also note that modifying `qPtr` (copy of what is passed) won't affect local variables of `main`. – MikeCAT Oct 02 '20 at 18:31
  • @MikeCAT I'm new to C and don't understand what you mean by 'buffer' and I don't really see where I am dereferencing a pointer. – Busters Oct 02 '20 at 19:07

0 Answers0