-2

I'm trying to insert a new node at the beginning of a linked list but it seems to output an error even though I think the code is correct. Can someone please show me how to fix this error? This is my insert method which outputs error on her first line. So the error is in the malloc function line. This is the error.

struct node
{
  int data ;//or char or double sist e duash
struct  node* next;
};

 struct node* head;//krijoj nyjen head
 //metoda insert
 void Insert(int x){
 struct node* temp=(node*)malloc(sizeof(struct node));
 temp->data=x;
 temp->next=head ;
 head=temp;
}
Tab Alleman
  • 31,483
  • 7
  • 36
  • 52
Doen
  • 33
  • 1
  • 1
  • 6

2 Answers2

2

You don't have a type node. You have a type struct node. So the cast (node*) is invalid. Change it to (struct node*) or better remove it at all as explained in the answers to this famous question.

Community
  • 1
  • 1
Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61
0

in node N should be capital ....it is Node*

Anurag
  • 1
  • 1