I’m trying to make an implementation of a double linked list which connects to an array.
The struct that makes the array contains the list’s Head and Tail pointer.
typedef struct myStruct{
int code;
struct myStruct *Head;
struct myStruct *Tail;
}myStruct;
myStruct MyArray[10];
Here’s my double linked list:
struct myList
{
int data;
struct myList *previous;
struct myList *next;
}head;
struct myList *start =NULL;
On the following piece of code im getting the warning which i wrote on the title of the post
warning: assignment from incompatible pointer type
void add_neighbor_to_neighborList(struct neighborList *start,int code,int Data)
{
struct myList *newNode = (struct myList *) malloc (sizeof(struct myList )); /* creates a new node of the correct data size */
newNode->data = Data;
if (start == NULL) { /*WARNING!checks to see if the pointer points somewhere in space*/
MyArray[code].Head=newNode; //WARNING
newNode->previous=MyArray[code].Head;
}
else
{
MyArray[code].Tail->next=newNode; /*error: ‘struct myStruct’ has no member named ‘next’*/
newNode->previous=MyArray[code].Tail; //WARNING
}
/*if (newNode == NULL){
return NULL;
}*/
MyArray[code].Tail=newNode; //WARNING
newNode->next=MyArray[code].Tail; //WARNING
//return *start;
}
I’m looking at it so much time but still cant find whats wrong and what i should correct.
If you had any idea,I would appreciate that! Thanks anyway/in advance! 😉
MyArray[code].Head‘s type isstruct myStruct *.newNode‘s type isstruct myList *.struct myStruct *andstruct myList *are pointers to two different types, they are incompatible, that’s what your compiler is telling you.You probably wanted your
struct myStructto be defined like this:I’d suggest you to use more explicit type names so errors like that wouldn’t happen.
You could rename your
struct myStructtostruct myListand renamestruct myListtostruct myNode. Because it’s what they are, or seem to be.