If I call createnode(x) in main and then follow that with printNodes(); I will get an infinite while-loop that seems to be printing some memory address. I am guessing the issue lies in the fact that i set head = temp?
SinglyLinkedList *head = NULL;
void createNode(int data){
SinglyLinkedList *temp = malloc(sizeof(SinglyLinkedList));
temp-> data = data;
if(head == NULL){
head = temp;
return;
}
temp->next = head;
head = temp;
}
void printNodes(){
SinglyLinkedList *temp = head;
while ( temp != NULL ){
printf("%d\r\n",temp->data);
temp = temp->next;
}
}