I'm having some problems with adding to a dynamic linked list. Basically it seems like my first node is overwritten. Here is the code:
struct palNode {
int number;
int pointer_index;
char* solving_array;
int solved;
struct palNode* next;
}
And here is my add method:
struct palNode* add_palNode_from_keyboard(struct palNode* head, int num, int pos){
struct palNode* newnode = (struct palNode*) malloc(1 * sizeof(struct palNode));
struct palNode* current_node = head;
if (current_node == NULL)
{
head = newnode;
}
else
{
while ((*current_node).next != NULL)
{
current_node = (*current_node).next;
}
(*current_node).next = newnode;
}
(*newnode).number = num;
(*newnode).pointer_index = pos;
(*newnode).next = NULL;
printf("Operation completed\n");
return newnode;
}
And here are my questions: What am I doing wrong? Is there a more correct way of doing it? I have seen other similar questions but I still dont get them