Code:
#include <stdio.h>
#include <stdlib.h>
struct nodePayload{
int number;
};
struct node{
struct nodePayload *payload;
struct node *next;
} *headSingle, *tailSingle, *temp;
s_display_inorder(){
tailSingle->next = NULL;
temp = headSingle;
printf("\nSingle list:\n");
while (temp != NULL){
printf("Left to right output:\t%d\n", temp->payload->number);
temp = temp->next;
}
}
s_add(int z){
temp->payload = malloc(sizeof(struct nodePayload));
temp = malloc(sizeof(struct node)); //Crashes here
temp->payload->number = z;
if (headSingle == NULL){
headSingle = temp;
tailSingle = temp;
}
else{
headSingle->next = temp;
tailSingle = temp;
}
return;
}
main(int argc, char *argv[]){
headSingle = NULL;
tailSingle = NULL;
int i;
for (i=0; i<10; i++){
s_add(1);
}
s_display_inorder();
}
I just want it to put the nodes in a linked list.