I'm doing this exercise for my base c programming exam and I get this error: "Dereferencing pointer to incomplete type", using code::blocks. Here is my code:
struct listPlot{
char name[25];
char surname[25];
int age;
struct listplot *next;
struct listPlot *prev;
};
struct listPlot *list;
struct listPlot *init(void)
{
list=malloc(sizeof(list));
list->next=NULL;
list->prev=NULL;
return list;
};
struct listPlot *addElement(struct listPlot *input)
{
printf("\nNew element, Name:\n");
gets(input->name);
printf("\nSurname:\n");
gets(input->surname);
printf("\nAge:\n");
scanf("%d", &input->age);
struct listPlot *newElement=malloc(sizeof(list));
*input->next=*newElement; //This is the line where the error occurs
newElement->next=NULL;
*newElement->prev=*input;
};
This function addElement
should take an listPlot pointer as an input, insert name surname and age, create a new element of the list and return it's pointer. I don't understand what's wrong with it... I apologize for my stupidity.
Another question, if i write input->next=newElement;
instead of *input->next=*newElement;
I get no error but a warning: "assignment from incompatible pointer type [enabled by default]". I'm sorry again for my ineptness, but I must ask you what is the meaning of that and what is the difference between the two lines.
Hope you don't mind helping me and thank you in advance.