I'm new here so sorry for not providing all information I should to get help I need but here goes.
struct node {
int data;
struct node* next;
struct node* previous;
};
*currentB = MultByTen(*currentB); // this is a line in another function.
// currentB is a struct node with data it in.
struct node* MultByTen(struct node* current) {
struct node *newNode = malloc(sizeof (struct node));
newNode->data = 0;
newNode->next = NULL;
while (current->next != NULL) {
current = current->next;
}
newNode->previous = current;
current->next = newNode;
return current;
}
I'm getting "error: incompatible types when assigning to type ‘struct node’ from type ‘int’" from that one line of code I have comments next to. I'm returning a struct node* so i don't know why I'm getting this error. Any ideas?
-EDIT: currentB is a linked list with data it in. it is
struct node* currentB = malloc(sizeof(struct node));
For the purposes of an example it is 1->2->3->4->NULL and what I want MultByTen is just to add a 0 to the end of the list so it'll become 1->2->3->4->0->NULL
I'm guessing currentB
is declared as struct node *currentB
? You try to assign a pointer to a structure, to an actual instance of the structure (*currentB
is not a pointer but the actual instance). The call is also wrong in this case.
The line should be:
currentB = MultByTen(currentB);
Note the missing *
.
May I suggest that you try to find a tutorial on pointers and how they are handled?