Link to home
Start Free TrialLog in
Avatar of Jad Dava
Jad Dava

asked on

Assignment from incompatible pointer type?

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;
    }
    else
    {
        (*q) -> back -> next = temp;
        (*q) -> back = temp;
    }
}

Open in new window


These are the headers that include the type defs.

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

Open in new window


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

Open in new window



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
  Otherwise
       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
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial