We help IT Professionals succeed at work.

Assignment from incompatible pointer type?

Jad Dava
Jad Dava asked
on
1,303 Views
Last Modified: 2017-03-29
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
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions