infinity-1 infinity-1 - 1 year ago 69
C Question

Error when trying to move to next element of a Linked List

I am dealing with linked lists, and am having issues moving to the next element of the Linked List. the error that I get is:

error: incompatible types when assigning to type 'item' from type 'struct item *

Here is the code:

typedef struct item
float size;
struct item *next;
} item;

item head, curr, tail;

... = (item*) malloc(sizeof(item));
curr =;

Thanks for your help.

Answer Source

Based in your description, you want to make curr the next node of the linked list (?).

In that case, you should assign the memory direction of curr to How, you may ask ?:

item head, curr;   // declaration of variables

head.size = 8;
curr.size = 5; = &curr; // making 'curr' the next node

Now, in the memory you will have something like this (memory addresses are just arbitraries numbers):

Memory example

NOTE: Pointers keep memory addresses. That's why you assign them the return value of malloc(), which give the memory direction of an available "memory chunk" with the expecified length.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download