this is the code for printing the two strings together but whenever I try to run it, there's a segmentation error but it compiles without any error, can anyone help?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node
{
char *data; //string data in this node
struct node *next; //next node or NULL if none
} Node;
void print(Node *head); //function prototype print
Node *push_node(Node x, Node *strlist);
int main ()
{
Node node1;
Node node2;
Node *list = NULL;
strcpy(node1.data, "world");
push_node(node1, list);
strcpy(node2.data, "hello");
push_node(node2, list);
print(list);
return 0;
}
void print(Node *head)
{
Node *p = head;
while (p != NULL)
{
printf("%s", p->data);
p = p->next;
}
}
Node *push_node(Node x, Node *strlist)
{
x.next= strlist;
return &x;
}