Im getting a segmentation error....can anyone help please
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char *data; struct node *next; }; int main() { struct node *head, *curr; int i=0; char *str=malloc(5); /* head=NULL; */ head=(struct node*) malloc (sizeof(struct node)); curr=head; printf("\nPlease enter data : "); for (i=0; i<5; i++) { str[i]=getchar(); if (str[i]=='\n') i=5; } strcpy(str, curr->data); printf("\n Data is : %s", curr->data); return 0; }