troubleshooting Question

Assignment from incompatible pointer type?

Avatar of Jad Dava
Jad Dava asked on
2 Comments2 Solutions1339 ViewsLast Modified:
This part of my program is giving me an incompatible pointer type warning on the fourth line:

void add(queue *q, int x)
    node_pointer temp;
    temp = (queue)malloc(sizeof(struct queuenode));
    temp -> data = x;
    temp -> next = NULL;

    if ((*q)==NULL)
        (*q) -> front = temp;
        (*q) -> back = temp;
        (*q) -> back -> next = temp;
        (*q) -> back = temp;

These are the headers that include the type defs.

typedef struct queuenode {
    int data;
    struct queuenode *next;
} *node_pointer;

typedef struct endpointer {
    node_pointer front;
    node_pointer back;
} *queue;

The pseudo code reads:
Receives queue via pass by reference and data to be added via pass by value
Allocates memory for new queuenode structure and assigns it to temp (a queue)
sets the data portion equal to the item to be added
sets the next pointer to point to the NULL
the new node will always point to NULL.
   If the queue is empty
        set both front and back to this new node
       attach it to to the next pointer of the back node
      move back pointer to this new node since it is now the last node in the queue
Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros