I am trying to learn struct in C. The code complies fine, when I try to input a value, it crashes. I tried with an int
member and it works.
typedef struct node{
char *productName;
int price;
struct node *next;
}node;
int main (){
node *head = (node*) malloc(sizeof(node));
printf("Enter a product name: ");
scanf("%s", &head->productName);
printf("Product entered:%s",head->productName);
//scanf("%d", &head->price); // this works
//printf("Price entered:%d",head->price);
}